Solved

How do I update constraints in a dataset

Posted on 2009-07-15
7
350 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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

18 Experts available now in Live!

Get 1:1 Help Now