brdrok
asked on
Cannot convert type 'char' to 'System.Data.DataRow'
is the message i receive when attempting to compile the following statement:
foreach(System.Data.DataRo w dr in myDataSet.Tables[0].Defaul tView.RowF ilter ="Status_FK = 1")
Basically, I'd like to use an existing dataset, apply the rowfilter, and then iterate through the filtered rows.
foreach(System.Data.DataRo
Basically, I'd like to use an existing dataset, apply the rowfilter, and then iterate through the filtered rows.
ASKER
Thanks unfortunately i get an error message that says:
Specified cast is not valid....
wish i could get a better error description....
Specified cast is not valid....
wish i could get a better error description....
I think it should be corrected a little bit to:
myDataSet.Tables[0].Defaul tView.RowF ilter ="Status_FK = 1";
foreach(System.Data.DataRo w dr in myDataSet.Tables[0].Defaul tView.Tabl e.Rows)
{
....
}
does that work?
myDataSet.Tables[0].Defaul
foreach(System.Data.DataRo
{
....
}
does that work?
ASKER
Hey Razzie,
I think the suggestion of yours is very close....at least I stopped getting the error message, however, the foreach statement seems to go through every single datarow and not the filtered rows. so i wrote a couple messagebox functions that shows me the number of records and here is that i came up with
MessageBox.Show(myDataSet. Tables[0]. DefaultVie w.Count.To String()); <--returns 12, which sounds about right
MessageBox.Show(myDataSet. Tables[0]. DefaultVie w.Table.Ro ws.Count.T oString()) ; <--returns 118, which are all the records
foreach(System.Data.DataRo w dr in myDataSet.Tables[0].Defaul tView.Tabl e.Rows)
{
//goes through all 118 records....
..........................
}
time for me to buy a good ado.net book :)
I think the suggestion of yours is very close....at least I stopped getting the error message, however, the foreach statement seems to go through every single datarow and not the filtered rows. so i wrote a couple messagebox functions that shows me the number of records and here is that i came up with
MessageBox.Show(myDataSet.
MessageBox.Show(myDataSet.
foreach(System.Data.DataRo
{
//goes through all 118 records....
..........................
}
time for me to buy a good ado.net book :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Snarf0001:
thanks...works really well right now. If you don't mind explaining in layman's term...what exactly is the difference between the RowFilter and the "Select" methods?
thanks
thanks...works really well right now. If you don't mind explaining in layman's term...what exactly is the difference between the RowFilter and the "Select" methods?
thanks
No problem.
The rowfilter is used on the dataview, which generally is used for filtering on bound controls, ie eliminating rows from a bound drop down or something like that. Dataviews CAN be used for processing data like you want to, but it's more of a pain, as that's not really what they were designed to do.
The .select will do basically the same thing as the rowfilter, but it's performed on the actual datatable itself, not the dataview, and will return an array of datarows for processing or whatever you might want.
Primarily, rowfilter acts on the view, and is used for changing display, .select acts on the table, returns an external set for processing.
The rowfilter is used on the dataview, which generally is used for filtering on bound controls, ie eliminating rows from a bound drop down or something like that. Dataviews CAN be used for processing data like you want to, but it's more of a pain, as that's not really what they were designed to do.
The .select will do basically the same thing as the rowfilter, but it's performed on the actual datatable itself, not the dataview, and will return an array of datarows for processing or whatever you might want.
Primarily, rowfilter acts on the view, and is used for changing display, .select acts on the table, returns an external set for processing.
ASKER
I think I understand....basically when using the .select...we are making another call to the database....but when using the rowfilter...the processing is being done on the cpu and no call to database is being made...
no no, the select is not going back to the db. The datatable itself is still in memory in the app, with all of it's datarows. Each one can have multiple dataviews, which just play around with the data in memory in the datatable.
A select statement, will just make a collection out of certain rows in memory. Still no trip to the db.
The datatable is the only thing that actually HAS the data, the view just manipulates it, and a .select just exposes some of it.
A select statement, will just make a collection out of certain rows in memory. Still no trip to the db.
The datatable is the only thing that actually HAS the data, the view just manipulates it, and a .select just exposes some of it.
ASKER
gotcha....those are some real knowledge gold nuggest today :)
is there a particular syntax that will release the collection of certain rows in memory or should i leave that up to the garbage collector?
too bad i already closed the question or else i could have added a few more points or uploaded a six pack of beer...
is there a particular syntax that will release the collection of certain rows in memory or should i leave that up to the garbage collector?
too bad i already closed the question or else i could have added a few more points or uploaded a six pack of beer...
lol
Leave the rows up to the garbage collector. They're still actually attached to the datatable, but I wouldn't really worry about that at this point.
Leave the rows up to the garbage collector. They're still actually attached to the datatable, but I wouldn't really worry about that at this point.
myDataSet.Tables[0].Defaul
foreach(System.Data.DataRo
{
....
}