0

I am not able to display any data in grid view,Its a blank datagrid The connection is open and everything is fine but data is not getting displayed!! I am a newbie

Imports System.Data.OleDb

Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.Open()

    Dim dvginfo As DataGridView

    Dim table As New DataTable("Address")

    Dim da As New OleDbDataAdapter("Select * FROM Address", con)
    Dim dtrow As DataTable
    da.Fill(table)
    If table.Rows.Count = 0 Then
        Return
    End If



    For Each dtrow In table.Rows
        dvginfo.Rows.Add()
        dvginfo.Rows(dvginfo.RowCount - 1).Cells("colFirstname").Value = dtrow("Firstname").ToString()
        dvginfo.Rows(dvginfo.RowCount - 1).Cells("colLastname").Value = dtrow("Lastname").ToString()
        dvginfo.Rows(dvginfo.RowCount - 1).Cells("colDOB").Value = Convert.ToDateTime(dtrow("DOB").ToString())
    Next
    dvginfo.ClearSelection()
    con.Close()
End Sub
End Class
jay
  • 33
  • 1
  • 9
  • 2
    Dim dvgInfo as DataGridView. Should either be removed and you should reference the grid you have on your form. Or if you creating it at run time, you need to add the control to the form. e.g. MyForm.Controls.Add(dvgInfo) – Tony Hopkinson Jan 21 '14 at 12:49

1 Answers1

0

Try this...

Imports System.Data.OleDb

Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.Open()

Dim dvginfo As DataGridView

Dim table As New DataTable("Address")

Dim da As New OleDbDataAdapter("Select * FROM Address", con)
Dim dtrow As DataTable
da.Fill(table)
dvginfo.DataSource = table
con.Close()
End Sub
End Class
chris_techno25
  • 2,401
  • 5
  • 20
  • 32