0

I am busy on a school assignment and I have a basic access database that consists of three tables. Book, Reader and BookRated where as BookRated is the intersection table with Primary keys userName from Reader and ISBN from Book make up the composite primary key for BookRated(as foreign keys).

I am trying to insert information into the BookRated table but get the following error

System.Data.OleDb.OleDbException: You cannot add or change a record because a related record is required in table 'Book'.

bool added;

    int i;
    conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
                                Data Source =" + Server.MapPath("App_Data\\BookRateInitial.mdb"));
    conn.Open();

    OleDbCommand cmd2 = conn.CreateCommand();
    cmd2.CommandText = @"INSERT INTO bookRated([frnISBN], [title], [rating], [review], [frnUserName])
                      VALUES(@ISBN, @title, @rating, @review, @userName)";
        //adding my parameters
    cmd2.Parameters.AddRange(new OleDbParameter[]
    {
        new OleDbParameter("@title", bookTitle),
        new OleDbParameter("@rating", rating),
        new OleDbParameter("@review", review), 
        new OleDbParameter("@ISBN", isbn), 
        new OleDbParameter("@userName", userName),
    });
    added = true;
    i = cmd2.ExecuteNonQuery();
    conn.Close();
    return added;

for now all the values are string.

Any advice perhaps as to where this error comes from?

1
  • Have you got a related record in book (ISBN)? Commented Nov 8, 2012 at 9:10

1 Answer 1

1

Check relationship of table bookRated. For more info on this error check Microsoft Support Site

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.