asafblasberg
Programmer
Hello, I'd like to be able to use the DataReader to control each row manually and proceed to the next.
Like this:
Fetch my data, then put row 1 information in an ASP:LABEL, then go to the next row (row 2) and put that information in anther label. If there is NULL data in next row, don't do anything.
Anyway to do this? (I do not want to use a datalist, because I'm trying to do something else here).
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected strConn as String
Sub Page_Load(sender As Object, e As EventArgs)
strConn = ConfigurationSettings.AppSettings("myseting")
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(strconn)
Dim queryString As String = "SELECT * from data where category = 2"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
[ HERE I WANT TO SAY, SELECT FIRST ROW, PUT THE INFORMATION IN AN ASP:LABEL LIKE THIS
myfirstlabel.text = datareader("whatever")
[ THEN GO TO THE NEXT ROW AND REASSIGN IT TO LABEL 2
mysecondlabel.text = datareader("whatever")
End Sub
</script>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<form id="asaf" runat="server">
<asp:label id="myfirstlabel" runat="server">
<asp:label id="mysecondlabel" runt="server">
" ETC ETC...."
</form>
</html>
THANKS!!!
Asaf
Like this:
Fetch my data, then put row 1 information in an ASP:LABEL, then go to the next row (row 2) and put that information in anther label. If there is NULL data in next row, don't do anything.
Anyway to do this? (I do not want to use a datalist, because I'm trying to do something else here).
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected strConn as String
Sub Page_Load(sender As Object, e As EventArgs)
strConn = ConfigurationSettings.AppSettings("myseting")
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(strconn)
Dim queryString As String = "SELECT * from data where category = 2"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
[ HERE I WANT TO SAY, SELECT FIRST ROW, PUT THE INFORMATION IN AN ASP:LABEL LIKE THIS
myfirstlabel.text = datareader("whatever")
[ THEN GO TO THE NEXT ROW AND REASSIGN IT TO LABEL 2
mysecondlabel.text = datareader("whatever")
End Sub
</script>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<form id="asaf" runat="server">
<asp:label id="myfirstlabel" runat="server">
<asp:label id="mysecondlabel" runt="server">
" ETC ETC...."
</form>
</html>
THANKS!!!
Asaf