1

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?

3 Answers 3

3

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

gvUnitSystem.AutoGenerateColumns = True
Sign up to request clarification or add additional context in comments.

2 Comments

Im an idiot, I dont know why I overlook little things like that. Yes that worked, and THANK you for correcting me on that.
before posting think then post
0

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.

Comments

0

You need to set the con (connection string).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.