prince shils

prince shils

  • NA
  • 4
  • 3.4k

Insert data into Foreign Key Table.

May 19 2012 11:45 PM
Hello Friends,
I want to insert data into foreign key Table with reference to the last entered primary key.

here is my code:

cmd.CommandText = string.Format("INSERT INTO Guest([FirstName],[LastName],[Adults],[Childs],[PhoneNo]) values(@fname,@lname,@Adults,@Childs,@PhNo) where [ReservationNo]==(Select @@IDENTITY From [Reservation])");
cmd.Parameters.Add("@fname", OleDbType.VarChar).Value = textBox1.Text;
cmd.Parameters.Add("@lname", OleDbType.VarChar).Value = textBox2.Text;
cmd.Parameters.Add("@Adults", OleDbType.Numeric).Value = textBox3.Text;
cmd.Parameters.Add("@Childs", OleDbType.Numeric).Value = textBox4.Text;
cmd.Parameters.Add("@PhNo", OleDbType.VarChar).Value = textBox5.Text;
cmd.ExecuteNonQuery();
MessageBox.Show("Data Insert!!");
con.Close();

Here is an error:
Syntax error (missing operator) in query expression '[ReservationNo]==(Select @@IDENTITY From [Reservation])'.

Note: I am using VS10, MSACCESS, C#

Answers (1)