Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataReader Control of Rows Help Thnk you!

Status
Not open for further replies.

asafblasberg

Programmer
Jun 22, 2004
21
US
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
 
Do you want to Populte the Labels Which are already there?

I think it is easier to generate the Labels Dynamically
And Add to the Form.

You can insert this code in the PageLoad.
Code:
 Label l1;
 while (dataReader.Read()) {
    if (!dataReader.IsDBNull(0)){
       l1=new Label();
       l1.Text=dataReader.GetString(0);
       asaf.Controls.Add(l1);
    }  
 }

I think you have to convert this into VB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top