When we write data in textbox related data wil be show in datagrid

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 853
Imports System.Data.SqlClient

Module Module1
Public con As New SqlConnection("server=localhost;user id=sa;database=pintu;password=;")
Public com As SqlCommand
Public ds As DataSet
Public sqlda As SqlDataAdapter
Public cmdbl As SqlCommandBuilder
Public dt As DataTable
Public dr As DataRow
Public str As String
End Module

Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
con.Open()
str = "select * from student"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Try
con.Open()
str = "select * from student where sname ='" & TextBox1.Text & "'"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
con.Close()
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Imports System.Data.SqlClient

Public Class Form2
Inherits System.Windows.Forms.Form

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try
con.Open()
str = "select * from student"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

Try
con.Open()
str = "select * from student where sname like '" & TextBox1.Text & "%'"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "student")
con.Close()
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

End Class

Comments or Responses

Login to post response