Home All Groups Group Topic Archive Search About

How to loop through rows of strongly typed dataset table

Author
30 Mar 2006 9:32 PM
moondaddy
In vb.net 1.1 I could do this:

Dim ds As dsEquip = GetDataset()

Dim dr As dsEquip.tbEquipRow
For Each dr In ds.tbEquip.Rows
    'Do something
Next

now in c# 2.0 I'm trying to do the same thing like this:

dsEquip ds = oData.PersonGetRecShort();
foreach (dsEquip.tbEquipRow dr in (dsEquip.tbEquipRow)ds.tbEquip.Rows)
{

}

I get a compile error saying:

Error 1 Cannot convert type 'System.Data.DataRowCollection' to
'ClientDataLayer.dsEquip.tbEquipRow' F:\Data\Sample
Projects\WWF\myFormState\BusinessLayer\Persons_BLL.cs 53 63 BusinessLayer

Using c# 2.0, what's the correct way to loop through all the rows in
ds.tbEquip.Rows?

Thanks.

Author
30 Mar 2006 9:49 PM
moondaddy
Found it.  It never fails.  I can search forever and not find the answer.
As soon as I post a question, I find it.  Found this one in a google search.

My problem is I was trying to loop through:
ds.tbEquip.Rows

but all I need to do is loop through:
ds.tbEquip

like this:
foreach (dsEquip.tbEquipRow dr in ds.tbEquip.Rows)
{
}

Anyone care to tall me if this is the difference between vb and cs, or
ado.net 1.1 and 2.0?


Show quote
"moondaddy" <moondaddy@nospam.nospam> wrote in message
news:e$%23VTFEVGHA.4792@TK2MSFTNGP14.phx.gbl...
> In vb.net 1.1 I could do this:
>
> Dim ds As dsEquip = GetDataset()
>
> Dim dr As dsEquip.tbEquipRow
> For Each dr In ds.tbEquip.Rows
>    'Do something
> Next
>
> now in c# 2.0 I'm trying to do the same thing like this:
>
> dsEquip ds = oData.PersonGetRecShort();
> foreach (dsEquip.tbEquipRow dr in (dsEquip.tbEquipRow)ds.tbEquip.Rows)
> {
>
> }
>
> I get a compile error saying:
>
> Error 1 Cannot convert type 'System.Data.DataRowCollection' to
> 'ClientDataLayer.dsEquip.tbEquipRow' F:\Data\Sample
> Projects\WWF\myFormState\BusinessLayer\Persons_BLL.cs 53 63 BusinessLayer
>
> Using c# 2.0, what's the correct way to loop through all the rows in
> ds.tbEquip.Rows?
>
> Thanks.
>

AddThis Social Bookmark Button