Typed dataSet Master-Details Table Form Issue RRS feed

  • Question

  • I try to create one form using Typed DataSet. The Form have Detail part and Datagridview .

    when I click save first time (CustomerMaster  Details,DataGridView  display OrderDetails) the Error Displays

    Error No: 547

    Description: The Insert Statement conflict with the FOREIGN KEY constraint "FK_OrderDetails_CustomerMaster".The conflict occurred in database "Sales",table "dbo.CustomerMaster",Column 'CustomerID.The Statement has been terminated.

    Result is CustomerMaster Table save the data but OrderDetails does'nt

    Then I Click Add(New)  button then try to save new customer and order details then working perfectly.

    My SaveButton Code Snippet Is Below


    Catch ex as Exception
    end try


    Please help


    • Moved by eryang Thursday, November 5, 2009 2:08 AM wrong forum (From:.NET Base Class Library)
    • Moved by VMazurModerator Thursday, November 5, 2009 10:47 AM (From:ADO.NET Data Providers)
    Wednesday, November 4, 2009 12:55 PM


  • Hi Saju,

    If you create a new project for this, will the exception occur again?

    When you add the datasource of master and details table, you get dataset like this,
    Department -- Master   Course -- Detail

    If you want to manipulate them, you can fist drag the gridview of Department. Then drag the datagridview under the root of Deparment.
    The save button's code will be as follows,


    In this way, you don't have to deal with the save code manually. Does this work for you?

    I guess your  problem is probably caused by the update order of the records. If you want to add your own logic of saving, be careful that your code may conflict with the generated code.

    You can also refer to this thread for some information,

    Best Regards
    Yichun Feng

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Tuesday, November 10, 2009 1:33 AM
    Sunday, November 8, 2009 3:50 AM