Data Grid
Data Grid
First thing you need to do is add reference to System.Data.OleDb namespace since I will
use OldDb data providers. if System.Data namespace is not present, you might want to add
this too.
Imports System.Data
Imports System.Data.OleDb
Now you use DataSource method of DataGrid to attached the DataSet data to the data grid.
Imports System.Data
Imports System.Data.OleDb
' some code here
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Northwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Customers",
myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
da.Fill(ds, "Customers")
' write dataset contents to an xml file by calling WriteXml method
' Attach DataSet to DataGrid
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
End Class