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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1298
  • Last Modified:

Custom TableAdapter Update Command

I have a vb.net form in Visual Sudio 2010 that is bound to an SQL table via a autogenerated (wizard) TableAdabpter and DataSet.

When change data I would like to customise the Update command to only update thos fields that have changed since the record was disconnected.

Is there a way of generating a custom SQL statment for the TableAdapter Update command?

Another option I considered was to use a direct update statment using ado.net to update the underlying database and not use the TableAdapter update command at all (and then call accept changes and reload the data...).
0
BorisMatthews
Asked:
BorisMatthews
  • 4
  • 4
1 Solution
 
CodeCruiserCommented:
>When change data I would like to customise the Update command to only update thos fields that have changed since the record was disconnected.

The TableAdapter only updates rows which have been modified. It uses the RowState property of each row to determine if the row has been modified.
0
 
BorisMatthewsAuthor Commented:
Yes, I am aware of that.  The question is can I customuse the update command so that it only updates the FIELDS with updated data.
0
 
CodeCruiserCommented:
Yes. You can catch the row updating event and execute your own code. Or you can loop through the rows yourself. Is there really a need for this?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BorisMatthewsAuthor Commented:
The reason I want to do this is to prevent a user over writing updates that will occur via bulk actions by other users.  Certain fields can ne viewed and updated by a user, record by record, that will also be updated via the bulk updates.  So if the user updates all fields then they will reset these fields to the values that they had when it wad disconnected from the database.
0
 
CodeCruiserCommented:
Why dont you change the update command so that it only includes the fields you want to allow?

http://www.codeproject.com/KB/database/TableAdapter.aspx
0
 
BorisMatthewsAuthor Commented:
Yes, I have seen this article and have implemented the concept for dynamically creating the select command but was unclear how to use this same concept for a custom update command, any pointers would be welcomed.
0
 
BorisMatthewsAuthor Commented:
Thanks for your help.  I have managed to get this working by looping through the columns in the updated row and comparing the original and updated versions compiled an sql statment which I then used to update the tableadapter.adapter.UpdateCommand property, I then called the update method.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now