L
Luc
Hi,
I want to bind the data provided by a sql statement in code-behind to a
gridview defined in the aspx file (i know it's possible to define a
sqldatasource in aspx).
How can i do that with this code here below?
Thanks for help.
Luc
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</form>
-------------------------------------
Imports System.Data.SqlClient
Partial Class a
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim connection As SqlConnection
Dim comd As SqlCommand
Dim connectionstr,stdnr As String
Dim dtreader As SqlDataReader
connectionstr =
ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString()
connection = New SqlConnection(connectionstr)
comd = New SqlCommand()
comd.Connection = connection
connection.Open()
comd.CommandText = "SELECT login FROM mytable"
dtreader = comd.ExecuteReader
If dtreader.HasRows Then
While dtreader.Read()
stdnr = dtreader.GetValue(0)
End While
End If
connection.Close()
End Sub
I want to bind the data provided by a sql statement in code-behind to a
gridview defined in the aspx file (i know it's possible to define a
sqldatasource in aspx).
How can i do that with this code here below?
Thanks for help.
Luc
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</form>
-------------------------------------
Imports System.Data.SqlClient
Partial Class a
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim connection As SqlConnection
Dim comd As SqlCommand
Dim connectionstr,stdnr As String
Dim dtreader As SqlDataReader
connectionstr =
ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString()
connection = New SqlConnection(connectionstr)
comd = New SqlCommand()
comd.Connection = connection
connection.Open()
comd.CommandText = "SELECT login FROM mytable"
dtreader = comd.ExecuteReader
If dtreader.HasRows Then
While dtreader.Read()
stdnr = dtreader.GetValue(0)
End While
End If
connection.Close()
End Sub