Solved

How do I update constraints in a dataset

Posted on 2009-07-15
7
353 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

910 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

23 Experts available now in Live!

Get 1:1 Help Now