[RESOLVED] syntax error help!
hi ,
I have a bit of a parameter problem which I cant spot!
1. I am populating a combobox a list of booknames/ folNos/ barcodes depending on which radio button is clicked using the BookID
2. Then with a button I execute a query to give me the balance. Somehow the bookID paramater is not being passed to this query. here is my code, and it gives this error.:
---------------------------------
Incorrect Syntax near @checkbook
---------------------------------
Code:
Private Sub TbViewStockbalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TbViewStockbalance.Enter
StockBalanceOption()
End Sub
Private Sub StockBalanceOption()
Dim strQuery As String
Try
'If Not cboBalance1.SelectedItem Is Nothing Then
strQuery = "Select bookName, bookID, folNo, barCode FROM tb_book where tb_book.obsolete='False'"
Dim da As New SqlClient.SqlDataAdapter(strQuery, MyConn)
Dim dtbook As New DataTable
MyConn.Open()
da.Fill(dtbook)
cboBalance1.DataSource = dtbook
If rbtitleB1.Checked = True Then
cboBalance1.DisplayMember = "bookName"
End If
If rbfolioB1.Checked = True Then
cboBalance1.DisplayMember = "folNo"
End If
If rbbarcodeB1.Checked = True Then
cboBalance1.DisplayMember = "barCode"
End If
cboBalance1.ValueMember = "bookID"
MyConn.Close()
'End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
MyConn.Close()
End Try
End Sub
Private Sub StockBalanceOptionSelected()
Dim strQuery As String
Try
If Not cboBalance1.SelectedItem Is Nothing Then
strQuery = "Select bookName, bookID, folNo, barCode FROM tb_book where tb_book.obsolete='False'"
Dim da As New SqlClient.SqlDataAdapter(strQuery, MyConn)
Dim dtbook As New DataTable
MyConn.Open()
da.Fill(dtbook)
cboBalance1.DataSource = dtbook
If rbtitleB1.Checked = True Then
cboBalance1.DisplayMember = "bookName"
End If
If rbfolioB1.Checked = True Then
cboBalance1.DisplayMember = "folNo"
End If
If rbbarcodeB1.Checked = True Then
cboBalance1.DisplayMember = "barCode"
End If
cboBalance1.ValueMember = "bookID"
MyConn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
MyConn.Close()
End Try
End Sub
Private Sub radioButtonsChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBalance1.SelectedIndexChanged, rbtitleB1.CheckedChanged, rbbarcodeB1.CheckedChanged, rbfolioB1.CheckedChanged
txtviewBalance.Text = ""
StockBalanceOptionSelected()
End Sub
Private Sub btnViewBalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewBalBk.Click
GetCurrentBalance(cboBalance1, txtviewBalance)
End Sub
This is in a Module :
Code:
Public Sub GetCurrentBalance(ByVal cbobook As ComboBox, ByVal txtbox As TextBox)
Dim sql As String = ("Select stockBalance from tb_book where bookID = @checkbook")
Dim cmd As New SqlCommand(sql, MyConn)
'cmd.Parameters.AddWithValue("@checkBook", cbobook.SelectedValue)
Try
MyConn.Open()
txtbox.Text = (cmd.ExecuteScalar()).ToString 'displaying the data from the table
cmd.Parameters.Clear()
MyConn.Close()
Catch ex As Exception
MsgBox(ex.Message)
MyConn.Close()
End Try
End Sub