|
-
Jun 7th, 2008, 10:20 AM
#1
Thread Starter
Frenzied Member
using parameters in query string [resolved]
Hi,
My error states that I should be declaring @checkBook. I am assuming I am declaring it in [RED] so where's the mistake pls???
Also do I need to use an adapter in here cos I had a search and found this method but I am assuming I need to state my connection somewhere right?? How's that??
Also if someone knows of any good link where I could learn more about parameters please send me link.
many thanks
Code:
Private Sub CurrentBalanceShowD()
Dim cmd As New SqlCommand
Try
cmd.Parameters.AddWithValue("@checkBook", SqlDbType.Int).Value = cboBookD.SelectedValue cmd.Parameters.AddWithValue("@checkBook", bookFID)
MyConn.Open() 'opening the connection
cmd = New SqlCommand("Select stockBalance from tb_bookbalance where bookFID = @checkBook", MyConn) 'executing the command and assigning it to connection
txtcurrentD.Text = (cmd.ExecuteScalar()).ToString 'displaying the data from the table
MyConn.Close()
Catch ex As Exception
MsgBox(ex.Message)
MyConn.Close()
End Try
End Sub
Last edited by angelica; Jun 7th, 2008 at 10:54 AM.
-
Jun 7th, 2008, 12:54 PM
#2
Re: using parameters in query string [resolved]
You're doing the same thing here as you were doing in another thread I replied to. You're assigning to the same variable twice, thereby simply discarding the first object. First you create a SqlCommand:
vb Code:
Dim cmd As New SqlCommand
then you add a parameter to it:
vb Code:
cmd.Parameters.AddWithValue("@checkBook", SqlDbType.Int).Value = cboBookD.SelectedValue
then you simply discard that command and create a new one:
vb Code:
cmd = New SqlCommand("Select stockBalance from tb_bookbalance where bookFID = @checkBook", MyConn)
The first command is simply thrown away, and the parameter with.
-
Jun 7th, 2008, 04:09 PM
#3
Thread Starter
Frenzied Member
Re: using parameters in query string [resolved]
Yes,
Fixed that . Working lovely now. Mille grazie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|