By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Accessing a Row in a typed Dataset

P: n/a
I created a typed dataset from which I am trying to access the data. When I use the following code to access a row
string name =dataset.person[1].firstName
I receive an error System.IndexOutOfRangeException as if there are no rows. Yet when I dump the data to a file I receive (sample of file)
<?xml version="1.0" standalone="yes"?><Dataset1 xmlns="http://tempuri.org/Dataset1.xsd"><Table><accountNo>1</accountNo><firstName>John </firstName><lastName>Smith </lastName><middleInitial></middleInitial></Table><Table><accountNo>2</accountNo><firstName>Michael </firstName><lastName>Kimson </lastName></Table><Table><accountNo>3</accountNo><firstName>Lewis </firstName

What am I doing wrong. How should I access the Rows of data in the dataset. I also tried to loop through the rows with a foreach loop but apparently there is no enumerator for this class

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi George,

What's the table name? "person"?

Have you tried this:

string name =dataSet11.Tables["person"].Rows[1]["firstName"].ToString();
or
string name =dataSet11.Tables[0].Rows[1]["firstName"].ToString();

You can use the following code to loop through the rows:

foreach(DataRow dr in dataSet11.Tables[0].Rows)
{
Console.WriteLine(dr["firstName"].ToString());
}

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: Accessing a Row in a typed Dataset
thread-index: AcPrMoSkof0TG5XoQ8GJ/tjKOYEBEw==
X-Tomcat-NG: microsoft.public.dotnet.general
From: "=?Utf-8?B?R2VvcmdlIEdyb2RlbnR6aWs=?=" <ge****@adsc.com>
Subject: Accessing a Row in a typed Dataset
Date: Wed, 4 Feb 2004 07:21:10 -0800
Lines: 7
Message-ID: <33**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.general:123664
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.general

I created a typed dataset from which I am trying to access the data. When I use the following code to access a row:
string name =dataset.person[1].firstName;
I receive an error System.IndexOutOfRangeException as if there are no rows.
Yet when I dump the data to a file I receive (sample of file):
<?xml version="1.0" standalone="yes"?><Dataset1
xmlns="http://tempuri.org/Dataset1.xsd"><Table><accountNo>1</accountNo><firs
tName>John </firstName><lastName>Smith
</lastName><middleInitial></middleInitial></Table><Table><accountNo>2</accou
ntNo><firstName>Michael </firstName><lastName>Kimson
</lastName></Table><Table><accountNo>3</accountNo><firstName>Lewis
</firstName>

What am I doing wrong. How should I access the Rows of data in the dataset.
I also tried to loop through the rows with a foreach loop but apparently
there is no enumerator for this class.


Jul 21 '05 #2

P: n/a
Hi George

I think your table that has data is named Table and not person.
Do the check - look at the dataset.Tables[0].TableName property.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"George Grodentzik" <ge****@adsc.com> wrote in message
news:33**********************************@microsof t.com...
I created a typed dataset from which I am trying to access the data. When I use the following code to access a row: string name =dataset.person[1].firstName;
I receive an error System.IndexOutOfRangeException as if there are no rows. Yet when I dump the data to a file I receive (sample of file): <?xml version="1.0" standalone="yes"?><Dataset1 xmlns="http://tempuri.org/Dataset1.xsd"><Table><accountNo>1</accountNo><firs
tName>John </firstName><lastName>Smith
</lastName><middleInitial></middleInitial></Table><Table><accountNo>2</accou
ntNo><firstName>Michael </firstName><lastName>Kimson
</lastName></Table><Table><accountNo>3</accountNo><firstName>Lewis
</firstName>
What am I doing wrong. How should I access the Rows of data in the dataset. I also tried to loop through the rows with a foreach loop but
apparently there is no enumerator for this class.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.