Accessing a field in untyped DS

G

Guest

Hello,
I have an copied data set. I'm trying to access a field.

daOrder.Fill(dsOrderSheet);

DataSet dsCopy = new DataSet();

dsCopy = dsOrderSheet.Copy();

// How do you do this part?

output = dsCopy.Tables["orders"].Rows[0].ItemArray["orderDate"];

//or

output = dsCopy.Tables[0].Rows[0].ItemArray[1];

//neither work.

How is this done?

Thanks kindly for any advice on this
Ant
 
C

Cor Ligthert [MVP]

Ant,

output = dsCopy.Tables["orders"].Rows[0].Item["orderDate"].ToString();
output = dsCopy.Tables[0].Rows[0][1].ToString();//both should work assuming output is a string and that they exist.

I hope this helps,

Cor
 
G

Guest

Hi Cor,

as always, thanks for your help. I tried the string you supplied:

output = dsCopy.Tables["orders"].Rows[0].Item["orderDate"].ToString();

by both typing it in & pasting it in, however I get a compile error as it
doesn't recognize .Item as an existing collection. (Intellisense only offers
up an ItemArray collection.)

Is this because I'm using VS2003?

Thanks for your help
Ant


Cor Ligthert said:
Ant,
output = dsCopy.Tables[0].Rows[0][1].ToString();//both should work assuming output is a string and that they exist.

I hope this helps,

Cor
 
C

Cor Ligthert [MVP]

Ant,

Sorry this overloaded version is not in C# only in VB.Net, I was automaticly
expecting it was the same. So you would have to do it with the other sample.

To be sure did I try it in C#, the documentation is a little bit vague about
this.

I hope this helps,

Cor


Ant said:
Hi Cor,

as always, thanks for your help. I tried the string you supplied:

output = dsCopy.Tables["orders"].Rows[0].Item["orderDate"].ToString();

by both typing it in & pasting it in, however I get a compile error as it
doesn't recognize .Item as an existing collection. (Intellisense only
offers
up an ItemArray collection.)

Is this because I'm using VS2003?

Thanks for your help
Ant


Cor Ligthert said:
Ant,
output = dsCopy.Tables[0].Rows[0][1].ToString();//both should work assuming output is a string and that they exist.

I hope this helps,

Cor
 
M

Miha Markic [MVP C#]

Also, you don't need to call ToString() unless you want to get a value
converted to string.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Ant,

Sorry this overloaded version is not in C# only in VB.Net, I was
automaticly expecting it was the same. So you would have to do it with the
other sample.

To be sure did I try it in C#, the documentation is a little bit vague
about this.

I hope this helps,

Cor


Ant said:
Hi Cor,

as always, thanks for your help. I tried the string you supplied:

output = dsCopy.Tables["orders"].Rows[0].Item["orderDate"].ToString();

by both typing it in & pasting it in, however I get a compile error as it
doesn't recognize .Item as an existing collection. (Intellisense only
offers
up an ItemArray collection.)

Is this because I'm using VS2003?

Thanks for your help
Ant


Cor Ligthert said:
Ant,


//or

output = dsCopy.Tables[0].Rows[0][1].ToString();

//both should work assuming output is a string and that they exist.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top