Solved

newbie VB and SQL problem

Posted on 2004-08-18
4
141 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:jakyll
  • 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 400 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:jakyll
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now