[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Update Dataset

Posted on 2006-03-23
Medium Priority
Last Modified: 2010-04-16
I am using C# in .NET
i have a dataset called changedDS with some rows. (primary key for this is id and date)
And i have another dataset called UpdateDS with many rows from a table (single table with primary key id and date). (And i am using Commandbuilder for this dataset so that i can update the underlying table)
Now i need to update the UpdateDS with changedDS data where primary key fields match.
If you can provide sample code that would be really great!

Question by:CMT Michigan
  • 2
  • 2
LVL 41

Expert Comment

ID: 16271950
It sounds like you need to do a "join" operation between the two tables....  Take a look at the following link to see if I'm on the right track.

The C# Join Helper Class is at http://support.microsoft.com/default.aspx?scid=kb;en-us;326080

I presume that the schema is not the same between the two DataTables?   And that after you've performed the join you will interate thru the rows and copy the relevant columns?....   or are the schemas identical, and you could just replace the row?

As a matter of semantics, do you really have two different DataSets or do you have two different DataTables in one DataSet.   Currently, the ability to create relationships between DataTables is restricted to tables within the same DataSet.

Author Comment

by:CMT Michigan
ID: 16272147

Thanks for your reply.
The Schema is same. I have two diffterent Datasets. (Why am i doing this?). Because i am displaying the data from a SP using temp table (becuase user wants to see data in different ways, for example i have data in day level inthe databse, some times they want to see data in week level or month level for this i am summing up and displaying on the grid). So i can not update this data directly. So i have another dataset at day level just for update. So i thought i can grab the modified rows from the grid and match with the other dataset (the one i populated for update) and update.
LVL 41

Expert Comment

ID: 16274736
Well, you still could add the existing DataTable from one DataSet to the other DataSet....  it's just one line of code:


After that you could use the join helper class to essentially do an SQL join on the two tables.   Once the join in completed, you'd just loop thru the rows and copy the column data...

Author Comment

by:CMT Michigan
ID: 16306903
i figured it a way to do it. Whatever the changes on the grid i am populating to a dataset using getchanges and rowstatus
and then i am looping through this Dataset and creating a Datarow(on the dataset i created for update) using the Dataset select , then updating the values.


Accepted Solution

DarthMod earned 0 total points
ID: 16584906
PAQed with points refunded (150)

Community Support Moderator

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question