EDN Admin
Well-known member
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.
<pre class="prettyprint 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;[/code]
Any advice perhaps
Kind regards
View the full article
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.
<pre class="prettyprint 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;[/code]
Any advice perhaps
Kind regards
View the full article