in one Employee table have 3 fields Id,name and department and Id is primary key. And in another table name is a EmployeeSalary and that has a also 3 fields Id,EmpId and salary and EmpId should be foreign key. whenever i run the program at that time i am getting error "SQLEXCEPTION unhandled by user". And breakpoint is show on the SQLCOMMAND object. And this is the insert query.
What I have tried:
String query = "insert into dbo.Employee(Name, department) values(@Name, @Department)";
SqlCommand cmd = new SqlCommand(query,con);
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@Department", DropDownList1.Text);
cmd.CommandText = query;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
con.Open();
String secondQuery = "insert into dbo.EmployeeSalary(Salary) values(@Salary)";
SqlCommand secondCmd = new SqlCommand(secondQuery,con);
secondCmd.Parameters.AddWithValue("@Salary", txtsalary.Text);
secondCmd.CommandText = secondQuery;
secondCmd.Connection = con;
secondCmd.ExecuteNonQuery();
con.Close();