how to bind an query to a gridview programmatically?


L

Luc

Hi,

i want to bind programmatically the records of a select query to an existing
gridview. I can get the records via dtreader, but i don't know how to get
them into the gridview (which is created in the aspx file)

Thanks
Luc

My attempt:

connectionstr =
ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString()
connection = New SqlConnection(connectionstr)
comd = New SqlCommand()
comd.Connection = connection
comd.CommandText = "select field1 from table1"
connection.Open()

dtreader = comd.ExecuteReader
If dtreader.HasRows Then
While dtreader.Read()
lc = dtreader.GetString(0)
????
End While
End If

GridView1.DataSource = ???
GridView1.DataBind()
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top