473,417 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

DataTable Find/Update

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!

--
Sincerely,

Mark Fox
Nov 19 '05 #1
3 6324
DataView.Select returns an array of DataRowView objects. Why can't you use
those?

DataRowView[] rows = dv.Find(...);
rows[0]["SomeColumnName"] = "NewValue";

-Brock
DevelopMentor
http://staff.develop.com/ballen
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!

Mark Fox


Nov 19 '05 #2
Brock,

Thanks for your post. The reason I am not looking to use DataView.Select or
DataTable.Rows.Find is because they require a primary key to be added to the
table. The table does not have a primary key and I am not looking to add one
programmatically since the table will be large and it could be a problem with
speed. I have read that for speed, using DefaultView.Find is best. I am
just attempting to figure out how the integer returned corresponds to rows in
the table (i.e. how to access the row in the table using the returned
integer). Thanks for your help!

"Brock Allen" wrote:
DataView.Select returns an array of DataRowView objects. Why can't you use
those?

DataRowView[] rows = dv.Find(...);
rows[0]["SomeColumnName"] = "NewValue";

-Brock
DevelopMentor
http://staff.develop.com/ballen
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!

Mark Fox


Nov 19 '05 #3
I've figured this out. It's

myDataTable.DefaultView[FoundRow]["Name"] = "Joe";

instead of

myDataTable.DefaultView.Table.Rows[FoundRow]["Name"] = "Joe";
"Solel Software" wrote:
Brock,

Thanks for your post. The reason I am not looking to use DataView.Select or
DataTable.Rows.Find is because they require a primary key to be added to the
table. The table does not have a primary key and I am not looking to add one
programmatically since the table will be large and it could be a problem with
speed. I have read that for speed, using DefaultView.Find is best. I am
just attempting to figure out how the integer returned corresponds to rows in
the table (i.e. how to access the row in the table using the returned
integer). Thanks for your help!

"Brock Allen" wrote:
DataView.Select returns an array of DataRowView objects. Why can't you use
those?

DataRowView[] rows = dv.Find(...);
rows[0]["SomeColumnName"] = "NewValue";

-Brock
DevelopMentor
http://staff.develop.com/ballen
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!

Mark Fox


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rich G | last post by:
Hi - can anyone comment on why performance would be so slow to update a DataTable row a simple value? With 3000 rows, it takes 5 seconds, which is unacceptable. Sample code below. Suggestions?...
2
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really...
2
by: Alvin Bruney | last post by:
Anybody know for sure if the data table find is faster than building a loop routine. I'm thinking the find is syntactic sugar because it can't really build an index table can it? But then again...
1
by: TSA | last post by:
Hi all, Here's scenario: Table 1: Table1_pk A B C Table2_fk
4
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1,...
2
by: Fred W. | last post by:
I wondering if there is a way to determine which objects are bound to my DataTable. I update my DataTable from a thread. My DataTable is bound to a DataGrid in my main UI. Apparently I will need to...
1
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row...
4
by: Arne Beruldsen | last post by:
I just can't seem to get the datagridview to update. I'm using 2005 vb.net Here's my code for loading the grid (works fine) and my attempt at updating via a save button... Private SxAdapter...
1
nev
by: nev | last post by:
Here is what I've been doing... .DataSet.DTT.AddDTTRow("hello", "world") .DTTTableAdapter.Update(.DataSet.DTT) But when I check my MySQL Database, Field1 = "" and Field2 = "" I was expecting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.