PC Review


Reply
Thread Tools Rate Thread

how to bind an query to a gridview programmatically?

 
 
Luc
Guest
Posts: n/a
 
      20th Jul 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").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()


 
Reply With Quote
 
 
 
 
Luc
Guest
Posts: n/a
 
      20th Jul 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").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()
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
how to bind array with gridview? Eric Microsoft ASP .NET 1 19th Mar 2009 12:44 PM
Using the #Bind method in a GridView Mark B Microsoft ASP .NET 1 9th Jan 2009 01:16 PM
GridView, Bind problem Jeff Microsoft ASP .NET 2 25th Nov 2008 09:37 AM
How do you bind a DirectoryInfo[] to a GridView Steve Kershaw Microsoft ASP .NET 3 29th Jun 2007 03:34 PM
Gridview and Bind() =?Utf-8?B?ZGF2ZQ==?= Microsoft ASP .NET 0 17th Nov 2006 03:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 AM.