Easy DataSet question

K

Keith Smith

I know I am missing something simple here. I have tried looking on Google
for a solution, but can't seem to do it. What is wrong with my code...?

foreach (DataRow myRow in yy.Tables[0].Rows)
{
MessageBox.Show((string)yy.Tables[0].Rows[myRow]["name"].ToString());
}

My goal is to MessageBox for each item in the "name" row.
 
N

Nicholas Paldino [.NET/C# MVP]

Keith,

When you enumerate through the rows, the enumeration returns the row,
not the indexer for the row. Because of that, you can just do this:

foreach (DataRow myRow in yy.Tables[0].Rows)
{
MessageBox.Show((string) myRow["name"]);
}

You don't need to call ToString on the return value of the indexer for
myRow if the type is a string, you can just cast it.

Hope this helps.
 
G

Guest

foreach (DataRow myRow in yy.Tables[0].Rows)
{
Messagebox(myRow["name"].ToString());
}

Yoa already have the row in myRow
 

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