Accessing a value from a dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using c# I'm trying to access a value from a dataset using the following code.

keyword.Text = myDataSet.Tables[0].Columns["keyword"].ToString();

but rather than getting the value at that location I just get the value
'keyword'.
I've also tried this without success.

keyword.Text = myDataSet.Tables[0].Rows[0].ToString();
 
that wont work in c#

but this will, I found the answer....

keyword.Text = myDataSet.Tables[0].Rows[0].ItemArray[0].ToString();
 
that wont work in c#

but this will, I found the answer....

keyword.Text = myDataSet.Tables[0].Rows[0].ItemArray[0].ToString();

Note you could also just use brackets [] instead of parens () in the
previous answer's code. That's the only difference in syntax for this
statement....well, that and the ; at the end of each statement :)
 
Note you could also just use brackets [] instead of parens () in the
previous answer's code. That's the only difference in syntax for this
statement....well, that and the ; at the end of each statement :)

Well actually the other difference is that Item(0) or Item[0] will not work
as well. It does not exist in c#. You need to use ItemArray ( which is crap
actaully ). Oh well.
=)
 
Just got it..

Label1.text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
--
:: KHAMAL ::


Protoculture said:
Note you could also just use brackets [] instead of parens () in the
previous answer's code. That's the only difference in syntax for this
statement....well, that and the ; at the end of each statement :)

Well actually the other difference is that Item(0) or Item[0] will not work
as well. It does not exist in c#. You need to use ItemArray ( which is crap
actaully ). Oh well.
=)
 

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

Back
Top