Click to See Complete Forum and Search --> : Problem working with DataGridView Control


kaushal.sharma
April 24th, 2006, 08:34 AM
Hello,

I have a access database (sheet_data.mdb) having table data with various columns. I can connect & create a data table from this database by following code.

Private Sub Editrecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Editrecord.Click
connection.Open()
str = "select * from data where Indate = '" & DTP1.Value.ToShortDateString & "' and username = '" & Label2.Text & "'"
Dim DataA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(str, connection)
Dim DataS As DataSet = New DataSet
DataA.Fill(DataS, "execData")
Dim DataT As New DataTable, DataR As DataRow, dataNR As DataRow
DataT.Columns.Add("username", GetType(System.String))
DataT.Columns.Add("Projectcode", GetType(System.String))
For Each DataR In DataS.Tables("execdata").Rows()
dataNR = DataT.NewRow
dataNR("username") = DataR("username")
dataNR("Projectcode") = DataR("Projectcode")
DataT.Rows.Add(dataNR)
Next
connection.Close()
End Sub

Now I want to popolate this data in my datagridview. Please help me to reaching my target. I m using VB2005 express edition.

Thx. Kaushal

aniskhan
April 25th, 2006, 05:35 PM
just use the datasource property
Me.DataGridView1.DataSource = ds.Tables(0)