Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Looping through dataset


Message #1 by rod@s... on Tue, 23 Jul 2002 17:25:22 +0800
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2322A.DE79F046
Content-Type: text/plain;
	charset="iso-8859-1"

Hi all,
I am trying to do a simple loop through a dataset in asp.net using VB.
In asp I would loop through using rs.EOF and haven't been able to find the
correct method for this in asp.NET.
I do not want a grid of any kind, I want to be able to access each field on
each record and deal with them seperately.
I have followed a several samples and keep hitting a brick wall.

The error report is
	BC30456: 'Rows' is not a member of 'System.Data.DataSet'.
	Line 12: Sub Page_Load() 
	Line 13: Dim dr as DataRow 
	Line 14: For Each dr In GetPageList().Rows 
	Line 15: response.write(dr("PageAddress").ToString() & "<BR>") Line 
	16: Next
Can anyone point me to a reference which outlines executing a select
statement and then looping through the record set.
Thanks in hope.
Rod



Message #2 by "Aaron Fleming" <aaronf@w...> on Tue, 23 Jul 2002 09:13:55 -0400
This is a multi-part message in MIME format.

------=_NextPart_000_003E_01C23229.45369C50
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Rob - could you post the rest of your code?

-----Original Message-----
From: rod@s... [mailto:rod@s...] 
Sent: Tuesday, July 23, 2002 5:25 AM
To: aspx_beginners
Subject: [aspx_beginners] Looping through dataset



Hi all, 
I am trying to do a simple loop through a dataset in asp.net using VB. 
In asp I would loop through using rs.EOF and haven't been able to find
the correct method for this in asp.NET. 
I do not want a grid of any kind, I want to be able to access each field
on each record and deal with them seperately. 
I have followed a several samples and keep hitting a brick wall. 

The error report is 
        BC30456: 'Rows' is not a member of 'System.Data.DataSet'. 
        Line 12: Sub Page_Load() 
        Line 13: Dim dr as DataRow 
        Line 14: For Each dr In GetPageList().Rows 
        Line 15: response.write(dr("PageAddress").ToString() & "<BR>")
Line 
        16: Next 
Can anyone point me to a reference which outlines executing a select
statement and then looping through the record set. 
Thanks in hope. 
Rod


--- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to



Message #3 by "Michael Spiering" <mspier@n...> on Tue, 23 Jul 2002 13:32:54 -0500
This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C2324D.73348E90
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Looping through datasetIf you are only going to read through the data a
single time, you should use a datareader object rather than a dataset.  An
example of how to use that would be:

Do While myReader.Read()
  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0),
myReader.GetString(1))    ' fields are indexed ...
Loop
myReader.Close()

To loop through a dataset, you could use an index to the rows collection:

With objDataSet.Tables(0)                    '  here's the problem (?)
    For intCounter = 0 to .Rows.Count - 1
        strResult = .Rows(.intCounter).Item(0).ToString  & " " & ...
' etc.  Again, the fields are indexed

' Also:  .Rows(intCounter).Item("fieldName").ToString
        Console.WriteLine(strResult)
    Next
End With

The error message you got suggests that you are expecting to find Rows in
DataSets.  Instead Rows are in Tables and Tables are in DataSets (which are
not quite like the ADO Recordsets we are used to).

Hope it helps.
  -----Original Message-----
  From: rod@s... [mailto:rod@s...]
  Sent: Tuesday, July 23, 2002 3:25 AM
  To: aspx_beginners
  Subject: [aspx_beginners] Looping through dataset


  Hi all,
  I am trying to do a simple loop through a dataset in asp.net using VB.
  In asp I would loop through using rs.EOF and haven't been able to find the
correct method for this in asp.NET.
  I do not want a grid of any kind, I want to be able to access each field
on each record and deal with them seperately.
  I have followed a several samples and keep hitting a brick wall.

  The error report is
          BC30456: 'Rows' is not a member of 'System.Data.DataSet'.
          Line 12: Sub Page_Load()
          Line 13: Dim dr as DataRow
          Line 14: For Each dr In GetPageList().Rows
          Line 15: response.write(dr("PageAddress").ToString() & "<BR>")
Line
          16: Next
  Can anyone point me to a reference which outlines executing a select
statement and then looping through the record set.
  Thanks in hope.
  Rod


  --- Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to


Message #4 by rod@s... on Wed, 24 Jul 2002 08:58:36 +0800
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C232AD.3DC56D78
Content-Type: text/plain;
	charset="iso-8859-1"

Aaron,
Thanks for taking a look at it.
 
Sub Page_Load()
        Dim dr as DataRow
        For Each dr In GetPageList().Rows
           response.write(dr("PageAddress").ToString() & "<BR>")
        Next       
End Sub
 

  Function GetPageList() As System.Data.DataSet
        Dim connectionString As String = "server='localhost'; user id='sa';
password=''; Database='HomePage'"
        Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
 
        Dim queryString As String = "SELECT [HomePageDirectory].[ID],
[HomePageDirectory].[PageAddress], [HomePageDire"& _
"ctory].[PageLabel] FROM [HomePageDirectory]"
        Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
 
        Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New
System.Data.SqlClient.SqlDataAdapter(sqlCommand)
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)
 
        Return dataSet
  End Function
 
Thanks again,
Rod.



  Return to Index