Prev: Help with adding info to Gridview
Next: Maintaining the selected row after sorting an ASP.NET DataGridView
From: Luc on 20 Jul 2010 10:14 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 20 Jul 2010 10:36
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() > |