DataSet scan efficiency

  • Thread starter Thread starter Maya
  • Start date Start date
M

Maya

Hello,

I have a dataset i need to insert new datarow in if the row is new and
doesn't exist in the dataset, other wise i will only need to update the
existing row.

for example, dataset with "ID" and "Name" fields can have a new row
added if the row's ID is not already in the dataset.

Any idea what the most efficient way (light performance) is to achieve
this task? maybe using "foreach" would do the job but i think this
wouldn't be very efficient as this operation needs to be done every
couple of seconds and requires fast execution time.

Thanks,

Maya.
 
Try DataTable.Rows.Find that allows to find a row by using the primary
key...
 
Thanks Cor,

Just out of curiosity, would "find" be also a good solution to be used
in this scenario:


2 datasets have to be merged, both have the same fields "ID" and
"value", primary is "ID"

when merging a duplicate "ID", the "value" field will have a specific
formula to be applied as following:

DS1: ID: "1", Value: "2"
DS2: ID: "1", Value: "4"
MergedDS: ID: "1", Value: "8"

The example above merge the 2 ID records into 1 record with a value of
multiplying the first ID value with the second one.

I don't know if merge method would allow to apply custom calculation
when duplicate is found, but would find also do the job in this case?

Thanks,

Maya
 
Maya,

A merge, merges all values as exist or not exist from the to import
datatable into the existing datatable.

In other words
1 a and 1 b
2 c
Will result in
1b
2c

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top