473,472 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing a Row in a typed Dataset

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
2 2227
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KimD | last post by:
I'm filling a dataset with the return of a stored procedure. The dataset contains a number of tables which I am naming within the stored procedure, however when I try to access the tables using the...
3
by: Darren Clark | last post by:
I am trying to understand typed datasets more.... and i am stuck on a little problem I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes. the news has...
2
by: George Grodentzik | last post by:
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.firstName I receive an error...
3
by: Freeon | last post by:
Hi, I am looking for a way to sort a strong typed dataset. It would seem the most straightforward way is to use a dataview. The only problem is when I use the dataview I seem to loose the strong...
1
by: Optimus | last post by:
Hi everyone, I currently develop an application in vs.net 2005 with vb.net. I was trying to use typed dataset and I've got in trouble for converting untyped dataset into Typed DataSet. I don't...
2
by: Tony Girgenti | last post by:
Hello I developed and tested a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1. It uses a web form. I used the XML Designer to create an XML .XSD...
21
by: Peter Bradley | last post by:
Hi all, This post is sort of tangentially related to my earlier posts on configuration files for DLLs. Does anyone know how to create typed DataSets using VS2005's new DataSet designer, but...
3
by: Robert Bravery | last post by:
HI all, I have an xml file, I need to be able to read the data into strong typed dataset for further use in my application Can someone point me to documentation as to how I can do this. I have...
4
by: Rachana | last post by:
Hi, I have understood Data Sets but what is meant by typed/untyped/ strongly typed datasets. Can any one explain me or suggest any site/ article, to get these concepts (and their ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.