G
Guest
I have a stored procedure that insert data into a sql table. I need to get
the record identity for another process. When I execute the program I get
this message " System.FormException: Input string was not in a correct
format". The line with *** is where the proglem crashed, Please tell me what
I doing wrong??
SqlCommand cmd = new SqlCommand("InsertOwner-info", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@salutation_1", txtSal.Text));
cmd.Parameters.Add(new SqlParameter("@owner_fname_2", txtFname.Text));
cmd.Parameters.Add(new SqlParameter("@owner_lname_3", txtLname.Text));
cmd.Parameters.Add(new SqlParameter("@owner_address_4", tAddress.Text));
cmd.Parameters.Add(new SqlParameter("@owner_city_5", txtCity.Text));
cmd.Parameters.Add(new SqlParameter("@owner_state_6", txtState.Text));
cmd.Parameters.Add(new SqlParameter("@owner_zipcode_7", txtZcode.Text));
cmd.Parameters.Add(new SqlParameter("@owner_home_phone_8",
txtHphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_work_phone_9", txtWphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_cell_phone_10", txtCphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_emgr_phone_11", txtEphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_emgr_contact_12",
txtEcontact.Text));
cmd.Parameters.Add(new SqlParameter("@owner_email_13", txtEmail.Text));
cmd.Parameters.Add(new SqlParameter("@owner_fax_number_14", txtFphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_refered_by_15",
txtRefered.Text));
cmd.Parameters.Add(new SqlParameter("@pets_16", txtNpets.Text));
cmd.Parameters.Add(new SqlParameter("@animal_id_17", txtOnum.Text));
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Update Complete. [animal-info] " + conn +
" Successful.","");
}
rdr.Close();
cmdGetIdentity.CommandText = "SELECT @@IDENTITY";
cmdGetIdentity.Connection = cnKennel;
*** rsIdentity = int.Parse(cmdGetIdentity.ExecuteScalar().ToString()); ***
txtOnum.Text = System.Convert.ToString(rsIdentity);
cnKennel.Close();
the record identity for another process. When I execute the program I get
this message " System.FormException: Input string was not in a correct
format". The line with *** is where the proglem crashed, Please tell me what
I doing wrong??
SqlCommand cmd = new SqlCommand("InsertOwner-info", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@salutation_1", txtSal.Text));
cmd.Parameters.Add(new SqlParameter("@owner_fname_2", txtFname.Text));
cmd.Parameters.Add(new SqlParameter("@owner_lname_3", txtLname.Text));
cmd.Parameters.Add(new SqlParameter("@owner_address_4", tAddress.Text));
cmd.Parameters.Add(new SqlParameter("@owner_city_5", txtCity.Text));
cmd.Parameters.Add(new SqlParameter("@owner_state_6", txtState.Text));
cmd.Parameters.Add(new SqlParameter("@owner_zipcode_7", txtZcode.Text));
cmd.Parameters.Add(new SqlParameter("@owner_home_phone_8",
txtHphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_work_phone_9", txtWphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_cell_phone_10", txtCphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_emgr_phone_11", txtEphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_emgr_contact_12",
txtEcontact.Text));
cmd.Parameters.Add(new SqlParameter("@owner_email_13", txtEmail.Text));
cmd.Parameters.Add(new SqlParameter("@owner_fax_number_14", txtFphone.Text));
cmd.Parameters.Add(new SqlParameter("@owner_refered_by_15",
txtRefered.Text));
cmd.Parameters.Add(new SqlParameter("@pets_16", txtNpets.Text));
cmd.Parameters.Add(new SqlParameter("@animal_id_17", txtOnum.Text));
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Update Complete. [animal-info] " + conn +
" Successful.","");
}
rdr.Close();
cmdGetIdentity.CommandText = "SELECT @@IDENTITY";
cmdGetIdentity.Connection = cnKennel;
*** rsIdentity = int.Parse(cmdGetIdentity.ExecuteScalar().ToString()); ***
txtOnum.Text = System.Convert.ToString(rsIdentity);
cnKennel.Close();