Solved

How do I update constraints in a dataset

Posted on 2009-07-15
7
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
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
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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