G
Guest
Hello,
I have a basic question. I have a DataTable of information without a
database store (it's only in memory). I am looking to somehow query the
DataTable to find out which row(s) satisfy certain criteria and then update
the data in those rows, all without any sort of database access (no
DataAdapters or anything). The table does not have a primary key so I've
been using DataTable.DefaultView.Find to get the index of the row that
satisfies the criteria. This is also supposed to be faster than Select() or
other methods that require re-indexing the table, which I would like to avoid
since I have to do this for multiple queries. But once get the index, how do
I use it to access the row that was just found to update the data in it?
I've attempted
myDataTable.DefaultView.Sort = SortColumns;
int FoundRow = myDataTable.DefaultView.Find(FindValues);
if(FoundRow != -1)
myDataTable.Rows[FoundRow]["Name"] = "Joe";
and
myDataTable.DefaultView.Sort = SortColumns;
int FoundRow = myDataTable.DefaultView.Find(FindValues);
if(FoundRow != -1)
myDataTable.DefaultView.Table.Rows[FoundRow]["Name"] = "Joe";
where SortColumns is the string of columns (i.e. "FirstName, LastName") and
FindValues is the object array of values to search for (i.e. {"Joey","Jimbo"})
and neither work (the row that "Joe" is saved into does not match the
FindValues on the SortColumns fields, so it's obviously not the row that
Find() is finding). How do I get to the row that Find is finding? Thanks
for your help!
I have a basic question. I have a DataTable of information without a
database store (it's only in memory). I am looking to somehow query the
DataTable to find out which row(s) satisfy certain criteria and then update
the data in those rows, all without any sort of database access (no
DataAdapters or anything). The table does not have a primary key so I've
been using DataTable.DefaultView.Find to get the index of the row that
satisfies the criteria. This is also supposed to be faster than Select() or
other methods that require re-indexing the table, which I would like to avoid
since I have to do this for multiple queries. But once get the index, how do
I use it to access the row that was just found to update the data in it?
I've attempted
myDataTable.DefaultView.Sort = SortColumns;
int FoundRow = myDataTable.DefaultView.Find(FindValues);
if(FoundRow != -1)
myDataTable.Rows[FoundRow]["Name"] = "Joe";
and
myDataTable.DefaultView.Sort = SortColumns;
int FoundRow = myDataTable.DefaultView.Find(FindValues);
if(FoundRow != -1)
myDataTable.DefaultView.Table.Rows[FoundRow]["Name"] = "Joe";
where SortColumns is the string of columns (i.e. "FirstName, LastName") and
FindValues is the object array of values to search for (i.e. {"Joey","Jimbo"})
and neither work (the row that "Joe" is saved into does not match the
FindValues on the SortColumns fields, so it's obviously not the row that
Find() is finding). How do I get to the row that Find is finding? Thanks
for your help!