Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to bind an query to a gridview programmatically?

Reply
Thread Tools

how to bind an query to a gridview programmatically?

 
 
Luc
Guest
Posts: n/a
 
      07-20-2010
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").C onnectionString.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()


 
Reply With Quote
 
 
 
 
Luc
Guest
Posts: n/a
 
      07-20-2010
i found it:

GridView1.DataSource = dtreader

"Luc" <ll@nospam> schreef in bericht
news:O1%(E-Mail Removed)...
> 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").C onnectionString.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()
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
Bind multiple selections to a query John Hoge ASP .Net 2 11-30-2004 10:12 PM



Advertisments