473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Defau ltView.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.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);

if(FoundRow != -1)
myDataTable.Row s[FoundRow]["Name"] = "Joe";

and

myDataTable.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);

if(FoundRow != -1)
myDataTable.Def aultView.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 6333
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.Defau ltView.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.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Row s[FoundRow]["Name"] = "Joe";
and

myDataTable.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Def aultView.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
programmaticall y since the table will be large and it could be a problem with
speed. I have read that for speed, using DefaultView.Fin d 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.Defau ltView.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.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Row s[FoundRow]["Name"] = "Joe";
and

myDataTable.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Def aultView.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.Def aultView[FoundRow]["Name"] = "Joe";

instead of

myDataTable.Def aultView.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
programmaticall y since the table will be large and it could be a problem with
speed. I have read that for speed, using DefaultView.Fin d 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.Defau ltView.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.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Row s[FoundRow]["Name"] = "Joe";
and

myDataTable.Def aultView.Sort = SortColumns;
int FoundRow = myDataTable.Def aultView.Find(F indValues);
if(FoundRow != -1)
myDataTable.Def aultView.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
4196
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? string colName = "seg_qty"; for (int i=0; i<mwbView.Count; i++) { mwbView.Row.BeginEdit(); mwbView.Row = 0;
2
12088
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 slow my update code amounts to dataTable.BeginLoadData() dataSet.EnforceConstraints = false tr for(iRowHandle = 0; iRowHandle < iLimit;...
2
1190
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 what is the primary key for if it doesn't really build a table. I suspect it is more for filling the datakeys and isn't really related to the index....
1
1797
by: TSA | last post by:
Hi all, Here's scenario: Table 1: Table1_pk A B C Table2_fk
4
2303
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, Len(Application.ExecutablePath) - 14)
2
1662
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 perform my table update on the UI Thread or the DataGrid has issues. Ideally I would like the DataTable to tell me who is bound to it and then...
1
12111
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 in dataTable.Rows) { row = "xyz";
4
5261
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 As New OleDbDataAdapter() Private SxSource As New BindingSource() Private SxTable As New DataTable() Private Sub GetData(ByVal selectCommand As...
1
922
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 Field1 = "hello" and Field2 = "world" I tried adding...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.