none
problom with insert row into typed dataset RRS feed

  • Question

  • hey.

    i'm trying to insert a row into my typed dataset but i'm getting an exception about forigen key constrain
    the tables that causing the problom is:

    orders: orderID int,userID int -FK   ,TotalPrice Money
    userInfo: int userID int -PK, and some other fields

    here's my code

    comicsDs

     

    ds = new comicsDs();

    userAdpter.Fill(ds.UserInfo);

     

    UserInfoRow userRow=ds.UserInfo.AddUserInfoRow(Fname, lName, Email, address, phone, creditCard, shipDate);

     

    OrdersRow orderRow = ds.Orders.AddOrdersRow(arr.getTotalPrice(), userRow);

    userAdpter.Update(ds.UserInfo);

    orderAdpater.Update(ds);

    please help:)

    • Moved by VMazurModerator Monday, April 27, 2009 10:26 AM (From:ADO.NET Data Providers)
    Sunday, April 26, 2009 5:10 PM

Answers

  • thanks all

    actually the problem was in the definiton of the adapter and queries. i didn't notice the refresh my dataTable checkBox:)
    • Marked as answer by Elad_me Sunday, May 3, 2009 6:40 AM
    Sunday, May 3, 2009 6:40 AM

All replies

  • me again...

    BTW the exception is

    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Order_user". The conflict occurred in database "testKey", table "dbo.user", column 'UserId'.
    The statement has been terminated.
    Monday, April 27, 2009 12:36 AM
  • Check:

    1. That the data type/size of the UserID col in both tables are the same
    2. That the UserID value you're inserting into the Orders table exists in the UserInfo table.
    Only performance counts!
    Saturday, May 2, 2009 3:15 PM
  • The issue must be your userID is not existing in userInfo table.. Check again.
    -- Mark as answer if this was helpful! --
    Sunday, May 3, 2009 1:28 AM
  • thanks all

    actually the problem was in the definiton of the adapter and queries. i didn't notice the refresh my dataTable checkBox:)
    • Marked as answer by Elad_me Sunday, May 3, 2009 6:40 AM
    Sunday, May 3, 2009 6:40 AM