Solved

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

Posted on 2011-02-28
2
311 Views
Last Modified: 2012-05-11
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
Comment
Question by:cdemott33
2 Comments
 
LVL 8

Accepted Solution

by:
Anurag Agarwal earned 500 total points
ID: 34998558
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
 

Author Closing Comment

by:cdemott33
ID: 34998690
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace &lt; with < 14 55
Error in JQuery 5 37
Gridview alignment 1 8
rebind a grid after user clicks on node in treeview 1 13
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now