I have a data set that that I would like to call in a foreach loop that is a property. I do not want to use .table[“xxx”]
public DataSet run(string query)
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
string query = "select * from table";
foreach (DataRow row in run(query))
{
//
}
DataSet doesn’t have any method to return DataRow objects.
If you can’t specify the TableName returned you can use a numeric Index like this:
If your query might return more than one row you should loop thru all tables like so: