What adapter to use for DataSet query

A

Andrew Mueller

Hello,

Since I cannot query a DataSet directly, and I would like to maintain
it's data, how would I use an adapter (SqlDataAdapter or DataAdapter) to
query this DataSet.

Example: Could I?

SqlDataAdapter adapter = new SqlDataAdapter();

adapter.Fill(myDataSet);

adapter.SelectCommand = "Select * from Table where x = '';

foreach (DataRow dr in adapter.rows)
{
//whatever processing I want here...
}


Andrew Mueller
 
N

Nicholas Paldino [.NET/C# MVP]

Andrew,

You can not do it like this. If the criteria are simple enough, then
you can create a DataView against that DataTable and then set the RowFilter
property on the view to filter out rows that you do not want to process.
You can then cycle through the rows made available to you through the
DataView.

Hope this helps.
 
A

Andrew Mueller

Thanks...

Tried that and I am having some problem... Here is my code. {ds = DataSet
with data. The Table is DataSettings and one of the 'columns' is called
Temperature}
DataView dv = new DataView();

dv.Table = ds.Tables["DataSettings"];


if (ds != null)

{


dv.RowFilter = "Temperature = ''";


foreach (DataRow dr in dv.Table.Rows)

{

Debug.WriteLine(dr["MashNumber"]);

return dr["MashNumber"].ToString();

}

}



However, when I run this code, I get an error on the foreach statement that:

An unhandled exception of type 'System.Data.EvaluateException' occurred in
system.data.dll

Additional information: Cannot perform '=' operation on System.Double and
System.String.



Any ideas?


Thanks in advance,

Andrew Mueller

Nicholas Paldino said:
Andrew,

You can not do it like this. If the criteria are simple enough, then
you can create a DataView against that DataTable and then set the RowFilter
property on the view to filter out rows that you do not want to process.
You can then cycle through the rows made available to you through the
DataView.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andrew Mueller said:
Hello,

Since I cannot query a DataSet directly, and I would like to maintain
it's data, how would I use an adapter (SqlDataAdapter or DataAdapter) to
query this DataSet.

Example: Could I?

SqlDataAdapter adapter = new SqlDataAdapter();

adapter.Fill(myDataSet);

adapter.SelectCommand = "Select * from Table where x = '';

foreach (DataRow dr in adapter.rows)
{
//whatever processing I want here...
}


Andrew Mueller
 

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