none
Insert Anomaly occurs while saving related data RRS feed

  • Question

  • Dears,


    I have mimicked http://msdn.microsoft.com/en-us/vstudio/cc138241 in C#. I was successful while entering the orders one by one. When I had about twenty or so records, in random order, I have deleted a few records, edited a few. When I deleted all records and started to enter orders afresh, it started giving insert anomaly error (i.e., the parent record doesn't exist). I have checked in DatasetDesigner. Nothing seems to be a problem.

    Also, I would like to know why in DatasetDesigner (xsd) the identity fileds (say OrderID) have auto-increment seed and step as -1 by default. Beth Massi's demonstration of the same technique in VS2005 (Updating Related Tables) has a xsd in which seed and steps of auto-increment are set to 0 and 1. I am started to suspect if this were the cause of that insert anomaly, because, every time I enter a new order, I get the order id displayed as -1 (while it is supposed to be somewhere around 40). I also tried to set these values to 0 and 1 but to no avail.

    What is the problem? Please help.

    Regards,

    pvv

    • Moved by Jason Dot Wang Monday, July 23, 2012 9:24 AM This thread is about ADO.NET DataSet (From:Visual C# General)
    Friday, July 20, 2012 5:10 AM

Answers

  • Hi pvv140,

      Welcome to MSDN Forum Support.

      We're doing research on this issue. It might take some time before we get back to you.

      Sincerely,

      Jason Wang

     




    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Dear Jason,

    I can see how I can handle this scenario here: http://blogs.msdn.com/b/bethmassi/archive/2009/09/15/inserting-master-detail-data-into-a-sql-server-compact-edition-database.aspx

    This link says the SQL Server Compact Edition (Which I used in my case) does not allow the table adapter manager to do the work automatically. Hence some hard coding must be done.

    Meanwhile, I am using SQL Server Express edition database (.mdf). I hope all will be well now.

    Thanks for reply,

    V


    Regards, pvv

    Monday, July 23, 2012 11:18 AM

All replies

  • Hi pvv140,

      Welcome to MSDN Forum Support.

      We're doing research on this issue. It might take some time before we get back to you.

      Sincerely,

      Jason Wang

     




    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 23, 2012 6:10 AM
  • Hi pvv140,

      Welcome to MSDN Forum Support.

      We're doing research on this issue. It might take some time before we get back to you.

      Sincerely,

      Jason Wang

     




    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Dear Jason,

    I can see how I can handle this scenario here: http://blogs.msdn.com/b/bethmassi/archive/2009/09/15/inserting-master-detail-data-into-a-sql-server-compact-edition-database.aspx

    This link says the SQL Server Compact Edition (Which I used in my case) does not allow the table adapter manager to do the work automatically. Hence some hard coding must be done.

    Meanwhile, I am using SQL Server Express edition database (.mdf). I hope all will be well now.

    Thanks for reply,

    V


    Regards, pvv

    Monday, July 23, 2012 11:18 AM
  • Hi pvv140,

    Welcome to MSDN Forum.

    I'm glad to hear that you found the solution of this issue, and thanks for your sharing. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 25, 2012 3:19 AM
    Moderator
  • Hi pvv140,

    Welcome to MSDN Forum.

    I'm glad to hear that you found the solution of this issue, and thanks for your sharing. : )

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Dear Allen,

    I still have problems with this issue. I have examined the same process in the SQL server express (.mdf) and found that it is working perfectly fine.

    As far as I know in order to port my software that uses an mdf file, I ought to install the SQL Server Express edition on the client system which is bit worrying. But with sdf files I can easily supply a runtime engine. The point is my application is really small and I still think it is best served by either Access 2010 or SQL CE (i.e., file based).

    How can solve this problem in C# and SQL CE (or Access) over Win Forms?


    Regards, pvv


    • Edited by pvv140 Monday, July 30, 2012 7:30 AM
    Monday, July 30, 2012 7:30 AM
  • Hi pvv140,

    I'm afraid I could'd repro the issue. I've add a number of records and save, all success. Then, I try to add some records, and delete some previous records, add again, it still works find. I would appreciate if you can upload your exist code to SkyDrive and post the link here, I will help you to test the code and find the root cause.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 31, 2012 2:04 AM
    Moderator
  • Hi Allen,

    I see my post did not explain what I wanted. Really sorry. Let me rephrase my problem a bit.

    The solution I found should work with SQL CE. I agree. But I was hoping to find an easier solution, wherein I can be relieved of the hard coding to fetch the primary keys. My efforts did not yield me anything worthwhile.

    On the other hand an expert friend suggested me to use UIDs instead of auto-incrementing integer IDs as primary keys. This has solved the issue. But the issue on the other hand is, my primary key now tends to be intangible and hence I cannot use it as an index field (contrast this with the integer ID). So my dilemma is, even though this solution (using UIDs) works, it leaves a little void. That is to say, if Beth Massi's solution (The link I provided) were to be in C#, I would have helped me.

    I'm not that conversant with subtle technicalities of C# language so that I can recast the solution from VB to C#. Can anybody help me port that solution to C#?


    Regards, pvv

    Tuesday, July 31, 2012 2:20 AM
  • Hi pvv140,

    I've already write a C# version of the sample, please download it here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 31, 2012 6:34 AM
    Moderator