Click to See Complete Forum and Search --> : Moving through Recordsets in VB.NET


nolc
May 21st, 2002, 01:02 PM
Does anyone know how to move through a recordset in VB.NET? AND get a record count? I'm trying to get all the records in a table and throw them into a 2-dimensional array. Any ideas?

Iouri
May 21st, 2002, 07:15 PM
A disconnected Recordset is retrieved in much the same way as a forward-only Recordset. So is a Recordset
that uses a dynamic cursor. This is not the case with a DataSet, which requires, at least in the following
example, a DataAdapter to handle the data population. Thus, while ADO had common methods for creating
different kinds of Recordsets, ADO.NET has specific methods for creating different forms of data repositories.

' This is a Visual Basic 6 Dynamic Cursor Recordset Example
Function VB6DynamicRSExample(connStr As String, _
statement As String) As Recordset
Dim rs As New ADODB.Recordset
rs.Open statement, connStr, adOpenDynamic

Set rs = conn.Execute(statement)
Set VB6DynamicRSExample = rs
Set rs = Nothing
End Function

' This is a Visual Basic .NET DataSet Example
Function VBNETDataSetExample(ByVal connStr As String, _
ByVal statement As String) As DataSet
Dim adapter As New OleDbDataAdapter(statement, connStr)
Dim ds As New DataSet()

adapter.Fill(ds)
Return ds
End Function

'---navigate through table-----
Dim row As DataRow
For Each row In ds.Tables(0).Rows
' Do stuff
Next

Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
row = ds.Tables(0).Rows(i)
' Do other stuff
Next

nolc
May 22nd, 2002, 08:13 AM
tHANKS ONCE AGAIN......... ;)