473,386 Members | 1,610 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,386 software developers and data experts.

Update one DataTable from another

Hi I need to update a field (fldX) in one DataTable (dt1) where there is a
match on fldA in another DataTable (dt2).

Is the only way to do this by itterating through the DataRows of dt1,
serching dt2 for a matching fldA and if found do the update and then move on
to the next row?

Thanks Greg
Nov 21 '05 #1
8 5337
Greg,

You can use a relation and than use the childcollections and parent
properties.

I hope this helps,

Cor
Nov 21 '05 #2
Cor,
A relation will not update dt1, will it?
I need to update the field where there is a match and then later update the
field on records where there were no matches with data from a different
source.

So I assume the only way is itterating through the DataTables?

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
Greg,

You can use a relation and than use the childcollections and parent
properties.

I hope this helps,

Cor

Nov 21 '05 #3
Greg,

You can get a(the) child row(s) using a relation, the same is for the parent

http://msdn.microsoft.com/library/de...drowstopic.asp

I hope this helps,

Cor
Nov 21 '05 #4
Cor,
I must not be explaining this correctly.

I can see that I could display a child field and even retrieve it but that
is not adequate, I need to update the master table.

I start with a DataTable, SOs with 2 fields that contain 'Nulls', UnitsTo
and UnitsConv.

I need to populate these two fields.

Taking 1st Field as an example, UnitsTo, populating it involves:
find matching records in a Table ItemMaster. ItemMaster has fields including
ItemProd and ItemToUnits.
Matching records are found using SOProd = ItemProd And SOWhs = ItemWhs

First stage involves Updating [SOs].UnitsTo with value of
[ItemMaster ].ItemToUnits
Not all records in SOs has a matching record in ItemMaster so not all
records will be updated

Next stage involves Updating [SOs].UnitsTo with value from
[SOs].UnitsStocking

Updating [SO].UnitsConv is even more complicated.

I suppose that I can create a relationship between SOs and ItemMaster
Then itterate through SOs
and use the code in the link you provided to return the value of ItemToUnits
if there is a matching record
and use it to update SOs.UnitsTo
and if there is not a matching record then use SOs.UnitsStocking to update
SOs.UnitsTo

This is better than itterating both tables but still involves itterating
SOs.

Is that the way you would achieve the result?

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Greg,

You can get a(the) child row(s) using a relation, the same is for the parent
http://msdn.microsoft.com/library/de...drowstopic.asp
I hope this helps,

Cor

Nov 21 '05 #5
Greg,

In my opinion is one thing you would not be afraid of in a modern computer,
that is (normally) itterating. It takes mostly *no* time. When you compare
what a simple resizing of a window does, than you know why I write this.

Therefore in my opinion you would take the approach which is the most
comfortable for you. (Which you can easy maintain). I only gave you an
alternative.

Cor
Nov 21 '05 #6
Sorry but I can not see how the link you provided provides me a different
way to achieve the results that I am looking for.

Thanks anyway.
Nov 21 '05 #7
Greg,
Sorry but I can not see how the link you provided provides me a different
way to achieve the results that I am looking for.


For me that is obvious, with setting the right relation I can in one time
get the rows that are affected.

However nobody says that you would use that. All your replys look for me if
you don't want to have an answer, only somebody who is telling that your way
is the best way. And than you probably will not get here.

Cor
Nov 21 '05 #8
Greg,
I don't think that you can create complex relationships in a DataSet ie
where the relationship uses multiple fields.

If you just need to display the correct for the UnitsTo etc and that is not
in a DataGrid, you could do the logical selection when the record is
selected.

But if you need the data in a Grid or to update the Source DB I think you
will need to go about it the way you originally proposed, Record by record
doing the search, if found replace otherwise substitue.

Doug

"Greg Peck" <ma**@vodaphone.com.au> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
Cor,
I must not be explaining this correctly.

I can see that I could display a child field and even retrieve it but that
is not adequate, I need to update the master table.

I start with a DataTable, SOs with 2 fields that contain 'Nulls', UnitsTo
and UnitsConv.

I need to populate these two fields.

Taking 1st Field as an example, UnitsTo, populating it involves:
find matching records in a Table ItemMaster. ItemMaster has fields including ItemProd and ItemToUnits.
Matching records are found using SOProd = ItemProd And SOWhs = ItemWhs

First stage involves Updating [SOs].UnitsTo with value of
[ItemMaster ].ItemToUnits
Not all records in SOs has a matching record in ItemMaster so not all
records will be updated

Next stage involves Updating [SOs].UnitsTo with value from
[SOs].UnitsStocking

Updating [SO].UnitsConv is even more complicated.

I suppose that I can create a relationship between SOs and ItemMaster
Then itterate through SOs
and use the code in the link you provided to return the value of ItemToUnits if there is a matching record
and use it to update SOs.UnitsTo
and if there is not a matching record then use SOs.UnitsStocking to update
SOs.UnitsTo

This is better than itterating both tables but still involves itterating
SOs.

Is that the way you would achieve the result?

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Greg,

You can get a(the) child row(s) using a relation, the same is for the

parent

http://msdn.microsoft.com/library/de...drowstopic.asp

I hope this helps,

Cor


Nov 21 '05 #9

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

Similar topics

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...
4
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
4
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
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...
0
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
1
by: Craig Buchanan | last post by:
I created a TableAdapter (TA) in my VB 2005 project. I tested it to ensure that its CRUD functionality is what I expected it to be. I'm using the TA and its strongly-typed DataTable (DT) in my...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.