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"
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
> 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();
}
}
}
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 .....
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
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...