0

Something is wrong with the select query. How can I add the right thing after (where)?

Private Sub sal_b1_Click(sender As Object, e As EventArgs) Handles sal_b1.Click
    If ComboBox3.Text <> "" Then
        Try
            Me.Refresh()
            con.Open()
            ds = New DataSet
            tables = ds.Tables
            da = New OleDbDataAdapter("Select inv_sall2.outdate, inv_sall2.custName, inv_sall2.ac, inv_sall2.subtotal, inv_sall2.taf, inv_sall.itemName, inv_sall.quntity, inv_sall.itemPrice, inv_sall.Tottal From inv_sall INNER Join inv_sall2 On inv_sall.no = inv_sall2.invoceno WHERE (((inv_sall2.invoceno)= '" & ComboBox3.Text & "'));", con)
            da.Fill(Form2.hazemDataSet, "datatable1")
            Form2.Show()
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    Else
        MsgBox("please select the invoice number")
    End If
End Sub
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
hhaannyy
  • 13
  • 4
  • 2
    Does this answer your question? [How do I create a parameterized SQL query? Why Should I?](https://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i) – GSerg Oct 02 '21 at 13:35
  • Connections should be disposed in addition to closed. – Mary Oct 03 '21 at 05:20
  • Why do create a new DataSet and a variable to hold the Tables collection of that new DataSet and never use either of them? – Mary Oct 03 '21 at 05:23
  • If you are using a DataAdapter it will open and close the connection for you. I any case don't open the connection several lines before it is needed. – Mary Oct 03 '21 at 05:27

1 Answers1

0

Just change it like:

WHERE inv_sall2.invoceno = " & ComboBox3.Text & ";", con)
S.B
  • 13,077
  • 10
  • 22
  • 49
hhaannyy
  • 13
  • 4