how to search from textbox and fill specific columns of datagridview from sql database?

  • Thread starter Thread starter relief12
  • Start date Start date
R

relief12

Guest
i am trying to search itemcode by typing in textbox and i want to get specific coloums in same row from sql database. i have made coloumns with headers in datagridview and i want that searched data in that specific datagridview coloumns. my code is searching but adding new columns next to already made columns in datagridview but i want only searched data in already made columns. please tell me how to do this?


Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click

On Error Resume Next

Using cn As New SqlConnection("server= PANKAJ\SQLEXPRESS; database = pankaj billing software; integrated security=true")

Using cmd2 As New SqlCommand("select itemcode As 'Item Code', item,qty As Quantity, weight as Weight from stockdata Where itemcode = @itemcode;", cn)

cmd2.Parameters.AddWithValue("@itemcode", TextBox1.Text)

cn.Open()

Dim dr As SqlDataReader = cmd2.ExecuteReader()

dt.Load(dr)

DataGridView1.DataSource = dt



For Each row As DataGridViewRow In DataGridView1.Rows


cmd2.Parameters.Add("@item", SqlDbType.VarChar)
cmd2.Parameters.Add("@qty", SqlDbType.VarChar)
cmd2.Parameters.Add("@weight", SqlDbType.VarChar)


With cmd2

row.Cells(1).Value = .Parameters("@item").Value
row.Cells(2).Value = .Parameters("@qty").Value
row.Cells(2).Value = .Parameters("@weight").Value

End With
cmd2.ExecuteNonQuery()

Next

End Using
End Using

Continue reading...
 
Back
Top