How do I display a data table in a data grid?
The following code queries an MS Access Table, then displays all the columns of that table in a Data Grid.
'Establish a connection to the data source.
Dim ConnString As String
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Test.mdb"
Dim Conn As New System.Data.OleDb.OleDbConnection(ConnString)
Conn.Open()
Dim dapt As New System.Data.OleDb.OleDbDataAdapter("Table1", Conn)
Dim dst As New DataSet
dapt.Fill(dst, "Table1")
DataGrid1.SetDataBinding(dst, "Table1")
Conn.Close()
Upon running the above code, Table1 from the a "Test" database will be displayed in a DataGrid.
Written by Sandeep Mogulla, Webmaster at
www.startvbdotnet.com
Index