From: Luc on
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()


From: Luc on
i found it:

GridView1.DataSource = dtreader

"Luc" <ll(a)nospam> schreef in bericht
news:O1%23fjXBKLHA.5700(a)TK2MSFTNGP04.phx.gbl...
> 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()
>