• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

How to refresh a TableAdapter when changes are done to the DB/Stored Procedure

I've create a DAL using a dataset/tableadapter.  The TableAdapter uses a Stored Procedure for the initial SELECT statement.  I've had to make changes to this Stored Procedure and modify some of the columns that were returned.

Now when I attempt to run my code I get an error of...

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

The only way to fix the problem is to delted the TableAdaptor and recreate it.  This can't be the solution.  There must be a better way or, at least, I hope there is.

Is there a way to "refresh" the TableAdaptor when you make changes to your DB/Stored Procedure?
0
cdemott33
Asked:
cdemott33
1 Solution
 
Anurag AgarwalCommented:
hello cdemott33 ,

Refreshing Data in a DataSet

If you want to refresh the values in your DataSet with updated values from the server, use DataAdapter.Fill. If you have primary keys defined on your DataTable, DataAdapter.Fill matches new rows based on the primary keys, and applies the server values as it changes to the existing rows. The RowState of the refreshed rows are set to Unchanged even if they were modified before the refresh. Note that, if no primary key is defined for the DataTable, DataAdapter.Fill adds new rows with potentially duplicate primary key values.

If you want to refresh a table with the current values from the serve while retaining any changes made to the rows in the table, you must first populate it with DataAdapter.Fill, fill a new DataTable, and then Merge that DataTable into the DataSet with a preserveChanges value of true.
Refer to Link
0
 
cdemott33Author Commented:
Thank you!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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