Solved

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

Posted on 2011-02-28
2
310 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

13 Experts available now in Live!

Get 1:1 Help Now