Sunday, 22 January 2023

Data Adapter



Data Adapter can be considered a collection of command objects which act like an interface between the database and the dataset.

Example to show a table from database to Datahridview in windows form Application.


Dim da As OleDb.OleDbDataAdapter

Dim ds As New DataSet

da = New OleDb.OleDbDataAdapter("select * from CityMaster", con)

da.Fill(ds, “city”)

DataGridView1.DataSource = ds.Tables(“city”)


Example to fire multiple queries in Data adapter

Dim com As New OleDb.OleDbCommand

com.Connection=con

da=New OleDb.OleDbDataAdapter("select * from Student ",con)

da.Fill(ds,"Student")

com.CommandText="select * from Class "

da.SelectCommand=com

daCloth.Fill(ds,"Class")


Apply Search filter on Datagridview by typing in textbox

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

   Dim dv As New DataView(ds.Tables("Student"))

   dv.RowFilter = "city LIKE '%" & TextBox1.Text & "%'"

   grdView.DataSource = dv

End Sub

 Next Topic

No comments:

Post a Comment