Solved

How do I update constraints in a dataset

Posted on 2009-07-15
7
358 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
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.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server How-To Show Notes In First Row of Results 4 30
SQL Server / Update DB? 22 36
SQL Query 2 31
SQL - Curser to do an insert based on a select 2 10
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

860 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