Easy DataSet question

  • Thread starter Thread starter Keith Smith
  • Start date Start date
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.
 
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.
 
foreach (DataRow myRow in yy.Tables[0].Rows)
{
Messagebox(myRow["name"].ToString());
}

Yoa already have the row in myRow
 
Back
Top