i want to retrieve primary key of parent table and then send this key to child table,as they have one-one relationship
i've written code
int i;
string id = "SELECT MAX(c_id) FROM call_history";
SqlCommand com1 = new SqlCommand(id, conn);
SqlDataReader dr = com1.ExecuteReader();
if (dr.Read())
{
i = Convert.ToInt32(dr.GetValue(1));
}
strQuery1 = "INSERT INTO call_log(c_id,c_add)VALUES("+ i +",'"+textBox2.Text +"')";
SqlCommand commm = new SqlCommand(strQuery1, conn);
commm.ExecuteNonQuery();
but it is goiving an error on insert atement that
"Use of unassigned local variable 'i' "
this time i defined i globaly but still having the same problem...is there any problem in the insert statement??
have i written the sql command rite??/
--------------------------------------------------------------------------------