Results 1 to 6 of 6

Thread: [RESOLVED] syntax error help!

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved [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
    Last edited by angelica; Sep 17th, 2008 at 11:49 AM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width