I have four tables M_Division
Divsion_ID(primary key) Division
1 abc
2 xyz
M_Designation
Designation_ID(primary key) Designation
1 scientist
2 doctor
M_emp personal
empid(primary key) Divsion_ID(foreign key) Designation_ID(foreign key) emp_name
1 1 1 mike
2 2 2 justin
M_temp
empid(foreign key) Divsion_ID(foreign key) Designation_ID(foreign key) date purpose
1 1 1 12-06-2013 xyz
2 2 2 12-06-2013 abc
I want to Insert the foreign key ID's into the M_temp table... If I give a query like this,it gives me the foreign key constraint error.....
Insert into M_temp(EmpID,DivisionID,DesigID,date,purpose,reason,created_date) Select(EmpID,DivisionID,DesigID from M_emp_personal where Empid=@empid",conn);
purpose,date are the form fields in my ASP.NET and they need to be inserted in the M_temp along with the DivID DesigID and EmpID...thats the problem I am facing...I dont know how exactly to do this can somebody help me out?
This is the C# code
protected void btnSubmit_Click2(object sender, EventArgs e)
{
string RelaseDate = Calendar1.SelectedDate.Date.ToString();
SqlCommand cmd = new SqlCommand("Insert into T_TADA_tempform(EmpID,DivisionID,DesigID,date,purpose,reason,created_date) values(@EmpID,@DivisionID,@DesigID,@GPFNo,@date,@purpose,@reason), conn);
cmd.Parameters.AddWithValue("@EmpID", ddlname.SelectedValue);
cmd.Parameters.AddWithValue("@DivisionID", divisionID);
cmd.Parameters.AddWithValue("@DesigID", lbldiv.Text);
cmd.Parameters.AddWithValue("date", RelaseDate);
cmd.Parameters.AddWithValue("@purpose", ddlpurpose.SelectedValue);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
int cnt = cmd.ExecuteNonQuery();
conn.Close();
if (cnt == 1)
{
Response.Redirect("");
}
else
Response.Write("Form has not been submitted,Please Try again!");
}
}