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
string id = "SELECT MAX(c_id) FROM call_history";
SqlCommand com1 = new SqlCommand(id, conn);
SqlDataReader dr = com1.ExecuteRea der();
if (dr.Read())
{
int i = Convert.ToInt32 (dr.GetValue(1) );
}
strQuery1 = "INSERT INTO call_log(c_id,c _add)VALUES("+ i +",'"+textBox2. Text +"')";
SqlCommand commm = new SqlCommand(strQ uery1, conn);
commm.ExecuteNo nQuery();
but it is goiving an error on insert atement that
"Use of unassigned local variable 'i' "
i've written code
string id = "SELECT MAX(c_id) FROM call_history";
SqlCommand com1 = new SqlCommand(id, conn);
SqlDataReader dr = com1.ExecuteRea der();
if (dr.Read())
{
int i = Convert.ToInt32 (dr.GetValue(1) );
}
strQuery1 = "INSERT INTO call_log(c_id,c _add)VALUES("+ i +",'"+textBox2. Text +"')";
SqlCommand commm = new SqlCommand(strQ uery1, conn);
commm.ExecuteNo nQuery();
but it is goiving an error on insert atement that
"Use of unassigned local variable 'i' "
Comment