?
Solved

newbie VB and SQL problem

Posted on 2004-08-18
4
Medium Priority
?
149 Views
Last Modified: 2010-04-23
Hi,

I have a form with a few textboxes for user input.  The form is to remove quantity from a pallet.  I cannot seem to figure out how to query my database and update the quantity based on this information.

I want to select palletid, quantity from tblPallets where palletid = txtpalletid.text and then subtract the value of val(txtQuantity.text) from that pallet.

But which object so i use?  Do i do it via code or those drop in objects from the toolbar?  How to I get a textbox value into one of those toolbar sql objects?

Frustrated,
Dan
:-)
0
Comment
Question by:Dan Flood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 11836305
Well... a SQL statement would look like:

Dim strSQL as string

'Make sure it is number and not blank...
if IsNumeric(txtQuantity.text) and IsNumeric(txtPalletID.text) then
  if txtQuantity.text <> "" and txtPalletID <> "" then
     strSQL = "UPDATE tblPallets SET quantity = quantity - " & CInt(txtQuantity.text) & " where palletID = " & _
                    Cint(txtPalletID.text)
  endif
endif

then do a DataReader with EXECUTENONQuery to do the update...
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 1200 total points
ID: 11836734
Hi there..
if you want to do it drag and drop way...(I don't recommend though), follow these steps..
1) Drag n drop an SqlConnection object from the "Data" tab of the ToolBox.
2) Select it and go to its properties in the Property box. Click on the connection string, click New Connection and create the connection. Say the name of this control is  SqlConnection1
here is the code...

Sub ChangeData()
   Dim SqlStr As String="UPDATE tblPallets SET quantity = quantity - " & CInt(txtQuantity.text) & " where palletID = " & Cint(txtPalletID.text)
   Dim SqlCmd As New SqlCommand(SqlStr, SqlConnection1)
   Try
      SqlConnection1.Open()
      SqlCmd.ExecuteNonQuery()
      SqlConnection1.Close()
   Catch Ex As Exception
      MsgBox(Ex.ToString)
   End Try
End Sub


Now use this sub whenever you need it.
-Baan
0
 

Author Comment

by:Dan Flood
ID: 11841107
Thank you - both answers helped - is there a way to split points?
0
 
LVL 7

Expert Comment

by:natloz
ID: 11844305
You can split points.

Yes. Scroll down to the bottom of the question, just above the text box, and click the "Split Points" link. Select the radio button of the comment who you want to Accept as the Accepted Answer. Only one button can be selected. Set the point value (a text box above the comment) of how much you want this person to receive of the points. Then set the point values for each of the experts comments to whom you want to allocate points and these will be considered Assisted Answers in helping you resolve the issue. Double check your information and then click the Submit button at the bottom of the page. One note: the total points of the splits must equal the amount you asked the question for itself, and no person can receive fewer than 20 points.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question