In this post we learn about Search Queries in complete detail. How do we search in SQL Server through VB.NET. This is a very simple task for which we need the same four text boxes and a Picture box and a button. After that is to use the below coding as per video instruction. Search query is mainly used to find the data this coding we may need in different projects.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If TextBox1.Text = "" Then MessageBox.Show("First Search Data") Else Dim cmded As New SqlCommand cmded.Connection = cnoo cmded.CommandText = "SELECT * FROM Table2 WHERE number='" & TextBox1.Text & "'" Dim adapter As New SqlDataAdapter(cmded) Dim table As New DataTable() adapter.Fill(table) If table.Rows.Count() > 0 Then TextBox1.Text = table.Rows(0)(0).ToString() TextBox2.Text = table.Rows(0)(1).ToString() TextBox3.Text = table.Rows(0)(2).ToString() TextBox4.Text = table.Rows(0)(3).ToString() Dim img() As Byte img = table.Rows(0)(4) Dim ms As New MemoryStream(img) PictureBox1.Image = Image.FromStream(ms) MessageBox.Show("Record found!") Else MessageBox.Show("Record not found!") End If End If End Sub
 
Top