views:

1337

answers:

3

I have a datatable with verified 10 rows named dtable. I attempt to bind it to my gridview and nothing shows up on my asp.net page. Why do these relatively simple few lines not populate my gridview?

    Dim con As SqlConnection = Nothing
    Dim dTable As DataTable
    Dim dataAdapter As SqlDataAdapter
    Dim sqlcmd As String
    .......
    dTable = New DataTable
    dataAdapter = New SqlDataAdapter(sqlcmd, con)
    dataAdapter.Fill(dTable)

    'DATATABLE at this point has 10 rows in it, I verified that at runtime

    gvUnitSystem.DataSource = dTable
    gvUnitSystem.DataBind()

End Sub

What am I doing wrong?

+2  A: 

Have you made sure that the GridView has AutoGenerateColumns set to true?

gvUnitSystem.AutoGenerateColumns = True
JaredPar
Im an idiot, I dont know why I overlook little things like that. Yes that worked, and THANK you for correcting me on that.
A: 

This looks fine. Are you auto-populating columns or have you manually added columns in the designer? If it is the latter maybe none of the column fields match fields in your table.

mjmarsh
A: 

You need to set the con (connection string).

tom