Hello,
I've tried to populate my gridView from a database. The program starts but Gridview1 is empty. There is something wrong with tha way I build my dataTable I think. Hope somebody can give me advice or write any kind of a solutin.
Thank You!
p.s. Fname, SecondName, Phone, Lastname are fields from my Danni.mdb. And I think exactly there I have a mistake but I am not sure and I have absolutely no idea what is the mistake
Here is the source:
Code:
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
Dim connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand("SELECT * from MarkaNaKola", connection)
Dim adapter As New OleDb.OleDbDataAdapter(command)
Dim authors As New DataSet()
adapter.Fill(authors)
If authors.Tables.Count > 0 Then
Dim DTable As DataTable
Dim row As DataRow
'create a DataTable
DTable = New DataTable
DTable.Columns.Add(New DataColumn("FName", GetType(String)))
DTable.Columns.Add(New DataColumn("SecondName", GetType(String)))
DTable.Columns.Add(New DataColumn("LastName", GetType(String)))
DTable.Columns.Add(New DataColumn("phone", GetType(String)))
For Each row In authors.Tables(0).Rows
row = DTable.NewRow()
row(0) = row("FName").ToString()
row(1) = row("SecondName").ToString()
row(2) = row("LastName").ToString()
row(3) = row("phone").ToString()
DTable.Rows.Add(row)
Next
GridView1.Enabled = False
GridView1.DataSource = New DataView(DTable)
GridView1.Enabled = True
GridView1.DataBind()
'Dim Column As Data.DataColumn
'For Each Column In DTable.Columns
' Response.Write(Column.ColumnName & "<br>")
' Next
End If