Home All Groups Group Topic Archive Search About

Iterating through the records in a dataset

Author
6 Sep 2006 10:47 AM
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

Author
6 Sep 2006 11:18 AM
Truong Hong Thi
Collection of rows.

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

mark blackall wrote:
Show quoteHide quote
> 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
Author
6 Sep 2006 6:59 PM
Mythran
Show quote Hide quote
"mark blackall" <black***@btinternet.com> wrote in message
news:edm939$nk4$1$830fa7a5@news.demon.co.uk...
> 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
Author
6 Sep 2006 7:03 PM
Mythran
Show quote Hide quote
"mark blackall" <black***@btinternet.com> wrote in message
news:edm939$nk4$1$830fa7a5@news.demon.co.uk...
> 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