cannot insert the database SQL server

Apr 26 2016 5:08 AM
the insert query working for SQL SERVER 2008
insert into tblTotal(Id,User_Name,Company_Name,Product_Name,MRP,Salon_Cost,Qty,Total_Cost)values('1','Charu','hhwq','gfh','343','65','3','3546')
it can be working...
but my .Net page
string sql = "INSERT INTO tblTotal (Id,User_Name,Company_Name,Product_Name,MRP,Salon_Cost,Qty,Total_Cost) VALUES (@Id,@User_Name,@Company_Name,@Product_Name,@MRP,@Salon_Cost,@Qty,@Total_Cost)";
SqlCommand cmd = new SqlCommand(sql, con);
{
con.Open();
cmd.Parameters.AddWithValue("@Id", lblGrandTotal.Text);
cmd.Parameters.AddWithValue("@User_Name", lbUserName.Text);
cmd.Parameters.AddWithValue("@Company_Name", Wella.Text);
cmd.Parameters.AddWithValue("@Product_Name", g1.Cells[0].Text);
cmd.Parameters.AddWithValue("@MRP", g1.Cells[1].Text);
cmd.Parameters.AddWithValue("@Salon_Cost", g1.Cells[2].Text);
cmd.Parameters.AddWithValue("@Qty", Qty.Text);
cmd.Parameters.AddWithValue("@Total_Cost", Total_Cost.Text);
cmd.ExecuteNonQuery();
con.Close();
this code is some kind of error..

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__tblTotal__User_N__33D4B598". The conflict occurred in database "RESPONSIVE", table "dbo.tblResponsive", column 'User_Name'.
The statement has been terminated.

i didn't know what kind of mistake

Answers (9)