Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I'd like to programatically move through a table

0 views
Skip to first unread message

barret bonden

unread,
Dec 31, 2005, 6:58:53 PM12/31/05
to
I'd like to programatically move through a table (call it a recordset in
ADO ) and disply fields in a textbox. I've gotten as far as the code below
(which just loads a listbox) I assume I need to work with the dataadaptor ,
but have been unable to find info on the web as to how to do it - the hope
is to be able to work , record by record,; something like the .movenext
capacity in the recordset objects of DAO and ADO.

myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\t.mdb")

myConnection.Open()

'myCommand = New OleDbCommand("select * from main", myConnection)

Dim myDataAdapter As New OleDb.OleDbDataAdapter( _

"Select * from main", myConnection)

Dim myDataSet As New DataSet()

myDataAdapter.Fill(myDataSet, "main")

'Dim myReader As OleDb.OleDbDataReader

Dim DataViewManager1 As DataViewManager = myDataSet.DefaultViewManager

ComboBox1.DataSource = DataViewManager1

ComboBox1.DisplayMember = "main.First"


Cyril Gupta

unread,
Jan 1, 2006, 7:17:12 PM1/1/06
to
Hello,

Well, your code reads right till the time you open the DataAdapter, but
after it just seems to disintegrate. There's actually no Recordset kind of
object in ADO.Net. I think you need to concentrate on the DataSet, it is
Recordset's alternative in ADO.Net.

You can fill a DataSet using the DataAdapter and then you can iterate
through the Rows object of the DataSet. It is quite like the Recordset, but
the Update operations are significantly different.

Cheers
Cyril


Otis Mukinfus

unread,
Jan 2, 2006, 10:18:55 AM1/2/06
to
On Sat, 31 Dec 2005 18:58:53 -0500, "barret bonden"
<art...@networks-cc.com> wrote:

> I'd like to programatically move through a table (call it a recordset in
>ADO ) and disply fields in a textbox. I've gotten as far as the code below
>(which just loads a listbox) I assume I need to work with the dataadaptor ,
>but have been unable to find info on the web as to how to do it - the hope
>is to be able to work , record by record,; something like the .movenext
>capacity in the recordset objects of DAO and ADO.
>
>myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
>Source=C:\t.mdb")
>
>myConnection.Open()
>
>'myCommand = New OleDbCommand("select * from main", myConnection)
>
>Dim myDataAdapter As New OleDb.OleDbDataAdapter( _
>
>"Select * from main", myConnection)
>
>Dim myDataSet As New DataSet()
>
>myDataAdapter.Fill(myDataSet, "main")

[snip]

To this point you are doing it correctly.

This is as far as you need to go with gathering data from the
database.

What you want to do from here is loop through each row in the "main"
table.

Here is an example of looping through a table in C#:

using System;
using System.Collections.Generic;
using System.Text;
using TestConsole.SimpleLogDataSetTableAdapters;
using System.Data;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
SimpleLogDataSet ds = new SimpleLogDataSet();
BandTableAdapter ta = new BandTableAdapter();

ta.Fill(ds.Band);

for (int row = 0; row < ds.Band.Rows.Count; row++)
{
for (int col = 0; col < ds.Band.Columns.Count; col++)
{
Console.Write("{0}\t", ds.Band.Rows[row][col]);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}

Cindy Winegarden

unread,
Jan 2, 2006, 11:23:26 AM1/2/06
to
Hi Barret,

Try code like this:

For Each oRow In myDataSet.Tables(0).Rows()
'-- Do stuff here
Console.WriteLine(oRow.Item(0).Tostring())
Next

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_wi...@msn.com www.cindywinegarden.com


"barret bonden" <art...@networks-cc.com> wrote in message
news:zVEtf.3479$2j2....@fe11.lga...
> I'd like to programatically move through a table .....

Cor Ligthert [MVP]

unread,
Jan 2, 2006, 11:49:26 AM1/2/06
to
Barret,

An instanced dataset is a disconnected object that holds datatables in a
collection.

In fact is that datatable almost the same as a recordset, with the
difference that the datatable is disconnect.

Therefore
dim dt as datatable = ds.tables(0) 'now I have named ds.tables(0) as well dt
to make typing easy

dt.rows(0) 'is the first row
dt.rows(dt.rows.count-1) 'is the last row
dt.rows(1) 'is the second row

And to see all rows you can use a for index loop or a for each loop as Cindy
shows you.

Does this make it clear?

Cor


barret bonden

unread,
Jan 2, 2006, 6:12:56 PM1/2/06
to
Got it. Many thanks to all - Cindy, I looked all over the MS sites for
simple and complete examples of how to
*use* the datasets in this way - can you say something to someone at MS
about this ? (I've been trying for years) either I missed it or it's just
not there in this fashion ; I can't lean with out being able to play , and
one can't play without the whole bit of code that makes things work ...
again , thanks -

Dim orow As DataRow


For Each oRow In myDataSet.Tables(0).Rows()
'-- Do stuff here
Console.WriteLine(oRow.Item(0).Tostring())

' ComboBox1.Items.Add(orow.Item(2).ToString())
ComboBox1.Items.Add(orow.Item(2).ToString() + " " + orow.Item(1).ToString())
Next

"Cindy Winegarden" <cindy_wi...@msn.com> wrote in message
news:eVWR3j7D...@TK2MSFTNGP09.phx.gbl...

0 new messages