Solved

How do I update constraints in a dataset

Posted on 2009-07-15
7
357 Views
Last Modified: 2013-11-26
Hello, here is a question that is bugging me. There has got to be a good solution for it, but I couldn't find it. I am using Vb.Net in Visual Studio 2005 accessing data from Sql Server 2005.

Here is what I did that caused a problem:
1. I created a database in Sql Server 2005 with constraints
2. I created a dataset in Visual Studio
3. In Sql Server I changed the field definition, deleted the constraint,  changed the data, and created a new constraint that was incompatible with the old one.
4. Now I tried to fill the dataset in Visual Studio, but it produced an error: "Failed to enable constraints. One or more rows  contain values violating non-null, unique, or foreign-key  constraints." It appears that the dataset has a copy of the old constraint.

My question is this: How can I update the dataset with the new constraint without deleting the dataset and starting over? It doesn't matter to me whether I do it manually somehow or do it via code; it only needs to be done once.

Thanks for your consideration
0
Comment
Question by:TadSter
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 24859328
Can you post your code please
0
 
LVL 2

Author Comment

by:TadSter
ID: 24859497
Most of this is done without code, but here is the line that generates the error:
Dim da As New W2_Process.PayrollW2DataTableAdapters.W2DataTableAdapter
            da.Fill(dsAll.tbW2Data, Main.DataYear)

Open in new window

0
 
LVL 15

Expert Comment

by:spprivate
ID: 24859828
This blog should give you some insight (if you have not read it early)
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 15

Expert Comment

by:spprivate
ID: 24859831
0
 
LVL 2

Author Comment

by:TadSter
ID: 24860165
That is all good information, but doesn't address how to change constraints in a dataset.

I found this: http://msdn.microsoft.com/en-us/magazine/cc163877.aspx
It says: You can regenerate the class file by right-clicking in the XSD's designer view and selecting Generate DataSet

I couldn't find that in Visual Studio's designer view; anyway, I'm not sure if that would recreate constraints without recreating the dataset.
0
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
ID: 24862914
Try this
1) Click on the XSD file in the solution explorer
2) Click on the properties tab and check the Custom Tool Property. In
there you should find MSDataSetGenerator. If it's not there, type it
there
3) Once done right click the XSD file and click the menu item Run
Custom Tool.

http://bytes.com/groups/net-c/695740-visual-studio-dataset-designer-doesnt-regenerate-designer-cs-code
0
 
LVL 2

Author Closing Comment

by:TadSter
ID: 31603716
Great! I appreciate your help a lot. I did what you suggested with MSDataSetGenerator. It still did not work; It still threw the constraint exception.

I then checked the troubleshooting tips. I noted this one: "Clear datasets before loading them from view state. If there is data in the dataset when you load it, this exception may be thrown."

So I added Me.DataSet.Clear before the Fill statement and now it works fine. Whenever I disable the clear statement the exception returns. Apparently it clears the constraints as well. So I got my problem solved.

Grateful!
Thanks a lot!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

776 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