473,480 Members | 1,841 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 2228
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
1563
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
1405
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
366
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
2731
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
9331
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
2673
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
2388
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
3838
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
3088
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
7037
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,...
1
6732
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
6886
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
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
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
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.