Question Update one dataset/datatable with another dataset/datatable

Isuru

New member
Joined
Aug 10, 2010
Messages
4
Programming Experience
Beginner
Hi All,

Is it possible to update one datatable with a value from another datatable? If so, can some one provide me the code for it....

I have tried the same and have attached the txt file View attachment Code1.txt but I am not sure if I am following the right track..

Please share your expert advice on this...

Thanks & Regards,
Isuru
 
Thanks for the reply...

I doknow it is vb.net forum.. I have just attached the code for the reference for the experts..
I have just asked a simple question which can be answered without looking at the attachment also...If any expert views it and finds any flaw he can respond to it...Thats it...

Anyways thanks for ur valuable input....
 
You haven't asked as simple a question as you think. You've actually asked a very vague question. Inserting data into a DataTable is done in exactly the same way no matter where it comes from, so if you already know how to put data into a DataTable from some other source then you already know the answer to your question. If your question involves something specific than that then you'll have to tell us what that is.
 
Let me explain you my scenario.

I have two dataset
ds1 - Fields (RepID, Cname,Desc) - Rows (Approx 2.5 lakhs)
ds2 - Fields (IDno, Bname,NewValue) - Rows (Approx 3 lakhs)

I want to lookup the ds2.idno in ds1.repid and update ds1.desc in ds2.newvalue field.

I can achieve this while using for loop but this process takes a lot of time, so i wanted to know if we can update the dataset using some simpler way so that time consuming is less.

Thanks in advance.
 
Is there a particular reason that you have two DataSets? Is the data from two different databases? You could probably do it quickest if you did it with straight SQL right in the database if there's only one. If you must do it in a DataSet then you could probably get a speed boost using one DataSet containing both DataTables and a DataRelation between them.
 
There is no database involved in this routine.. I have two excel sheets from where I am creating the dataset.

Can you explain the below snippet. How will I be able to apply the same in my scenario.
<snip>
If you must do it in a DataSet then you could probably get a speed boost using one DataSet containing both DataTables and a DataRelation between them.
<snip>
 
When you load the data from your Excel workbook, you're loading it into a DataTable. A DataSet doesn't contain data. A DataSet contains DataTables and DataRelations. Creating two DataSets like that is pointless. You either don't need a DataSet at all or you should put both DataTables in the same DataSet. The DataTables go in the Tables collection, then you can add a DataRelation to the Relations collection. When creating the relation you specify the parent and child tables and the parent and child columns. You can then loop through the rows in the child table and call GetParentRow on each one.
 
Let me explain you my scenario.

I have two dataset
ds1 - Fields (RepID, Cname,Desc) - Rows (Approx 2.5 lakhs)
ds2 - Fields (IDno, Bname,NewValue) - Rows (Approx 3 lakhs)

What's a lakh?


I want to lookup the ds2.idno in ds1.repid and update ds1.desc in ds2.newvalue field.
Let's assume by "dataset" you actually mean "datatable"

Make ds1.repid a primary key
Use How to: Locate a Specific Row in a DataTable to find the row as you loop through ds2, writing whatever values to whatever row you want (i couldnt quite work out what you want to update)


I can achieve this while using for loop but this process takes a lot of time
When you add a primary key, .NET maintains a hashtable of the column values so it can find things quickly
 
Back
Top