By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Update one DataTable from another

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
Greg,

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

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.