Iterating through the records in a dataset

M

mark blackall

Hi all,

I am new to vb.net and I am trying to use the vb.net components, rather than
relying on the VB6 compatibility stuff with which I am more familiar.

However, I seem to have fallen at the first hurdle. I have created a
dataset linked to a single SQL table and would like to iterate through the
records in it, it, changing one of the fields as I go, but I can't seem to
find a way of doing this. I guess all the records are in a collection of
some sort but I can't seem to access them.

Any help gratefully received.

Thanks

Mark
 
T

Truong Hong Thi

Collection of rows.

For Each row as DataRow in theDataSet.Tables[0].Rows
 
M

Mythran

mark blackall said:
Hi all,

I am new to vb.net and I am trying to use the vb.net components, rather
than relying on the VB6 compatibility stuff with which I am more familiar.

However, I seem to have fallen at the first hurdle. I have created a
dataset linked to a single SQL table and would like to iterate through the
records in it, it, changing one of the fields as I go, but I can't seem to
find a way of doing this. I guess all the records are in a collection of
some sort but I can't seem to access them.

Any help gratefully received.

Thanks

Mark

I had trouble understanding ADO.Net when I switched from ADODB using VB6 :)

Look at the big differences between the two in order to help understand
them. ADODB contain recordsets that you can update directly and calling a
single Update method on the Recordset will update the database. ADO.Net has
no such method.

A DataSet is NOT a recordset, nor should it be used as one. It helps me to
see a DataSet as an in-memory database. Just like a db, the DataSet
contains tables (stores of data). The DataTable
 
M

Mythran

mark blackall said:
Hi all,

I am new to vb.net and I am trying to use the vb.net components, rather
than relying on the VB6 compatibility stuff with which I am more familiar.

However, I seem to have fallen at the first hurdle. I have created a
dataset linked to a single SQL table and would like to iterate through the
records in it, it, changing one of the fields as I go, but I can't seem to
find a way of doing this. I guess all the records are in a collection of
some sort but I can't seem to access them.

Any help gratefully received.

Thanks

Mark

Oops, ignore my previous post...darn shift-enter!!!

What helps me is looking at DataSets as small, in-memory databases. Each
DataSet can contain one or more DataTable instances. Each DataTable contain
DataRows. The rows, when updated, do NOT update the SQL Server (or other
dbms) automatically. Instead, the in-memory db (DataSet/DataTable/DataRow)
is updated. When you want to commit (Update) the real dbms, you will need
to connect to the database (if no connection exists already), and using the
DataAdapter (ie: SqlDataAdapter) call the appropriate Update/Insert methods
passing either the DataRow, DataTable, or DataSet (forget which is
required).

Once you do get a handle on ADO.Net, I would recommend looking into the
Microsoft Patterns and Practices Enterprise Library Application Blocks (more
specifically, the Data Access Application Block). These blocks help
streamline code you would normally write to help normalize database
connection and access.

HTH,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top