Stuck? Need help? Ask questions on our forums.
*/
*/

How to Display a Data Table in a Data Grid

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
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings