I have SQL database table with following data:
BillNo Particular Price Unit Amount Taxamount Tax
2905 Airfreight 100.000 100 10000.000 0.000 0.000
2905 Customs 4500.00 1 0.000 4500.000 675.000
2906 THC 250.000 1 0.000 250.000 38.000
2906 XYZ 5000.00 1 5000.000 0.0000 0.0000
In a window form I have a textbox named Tbblbillto.Text
for searching by bill number, and a Datagrid. When I type the bill number in the textbox, how can I make the data from the SQL table be filtered against the bill number and then put it in the datagrid?
*Data Grid Table*
**Particular Price Unit Amount Taxamount Tax**
Private Sub Tbblbillto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbblbillto.TextChanged
Dim Cmd As New SqlClient.SqlCommand
Dim Con As New SqlClient.SqlConnection
Dim Rd As SqlDataReader
Con.ConnectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=dbase;Integrated Security=True;Pooling=False"
Cmd.Connection = Con
Con.Open()
Dim Row As New DataGridViewRow
Dim Int As Integer
Row = Dgvbillsa.Rows(Int)
Cmd.CommandText = "Select * from BillDetails Where BillNo = '" & Tbblbillto.Text & "'"
Rd = Cmd.ExecuteReader
Rd.Read()
If Rd.HasRows Then
Row.Cells(0).Value = Rd.Item("Particular")
Row.Cells(1).Value = Rd.Item("Price")
Row.Cells(2).Value = Rd.Item("Unit")
Row.Cells(3).Value = Rd.Item("Amount")
Row.Cells(4).Value = Rd.Item("TaxAmount")
Row.Cells(5).Value = Rd.Item("Tax")
End If
End Sub