G
Guest
I am inserting a record into a sql table and get two (2) indentical records
each time. I am using a stored procedure. What am I doing to cause this to
happen. In the stored procedure I have the line 'SELECT SCOPE_IDENTITY()'.
The code that I use to execute the stored procedure is here:
try
{
conn = new SqlConnection("Server=icc-server;DataBase=kennel;Integrated
Security=SSPI");
if (cnKennel.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand("InsertAnimal-info", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@owner_id_1", txtOid.Text));
cmd.Parameters.Add(new SqlParameter("@animal_tag_id_2", txtAnimalTag.Text));
cmd.Parameters.Add(new SqlParameter("@animal_implanted_id_3",
txtAnimalImpId.Text));
cmd.Parameters.Add(new SqlParameter("@sp_nu_4", cbSpNu.Text));
cmd.Parameters.Add(new SqlParameter("@pet_name_5",txtAnimalName.Text));
cmd.Parameters.Add(new SqlParameter("@pet_type_6", cbAnimalType.Text));
cmd.Parameters.Add(new SqlParameter("@pet_breed_7",cbAnimalBreed.Text));
cmd.Parameters.Add(new SqlParameter("@pet_sex_8", cbAnimalSex.Text));
cmd.Parameters.Add(new SqlParameter("@pet_weight_9", txtAnimalWeight.Text));
cmd.Parameters.Add(new SqlParameter("@pet_size_10", cbAnimalSize.Text));
cmd.Parameters.Add(new SqlParameter("@pet_color_11", txtAnimalColor.Text));
cmd.Parameters.Add(new SqlParameter("@pet_age_years_12",
txtAnimalAgeYears.Text));
cmd.Parameters.Add(new SqlParameter("@pet_age_months_13",
txtAnimalAgeMonths.Text));
cmd.Parameters.Add(new SqlParameter("@rate_14",
Convert.ToDecimal(cbRate.Text)));
cmd.Parameters.Add(new SqlParameter("@rate_type_15", cbRateType.Text));
cmd.Parameters.Add(new SqlParameter("@compatable_16", cbCompatable.Text));
cmd.Parameters.Add(new SqlParameter("@medical_condition_17",
txtAnimalMedicalCondition.Text));
cmd.Parameters.Add(new SqlParameter("@pet_location_18",
txtAnimalLocation.Text));
cmd.Parameters.Add(new SqlParameter("@pet_photo_19", pcAnimalPhoto.Text));
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Insert Complete. [animal-info] " + conn +
" Successful.","");
}
rdr.Close();
IdentityValue = Convert.ToInt32(cmd.ExecuteScalar());
osave = IdentityValue.ToString();
each time. I am using a stored procedure. What am I doing to cause this to
happen. In the stored procedure I have the line 'SELECT SCOPE_IDENTITY()'.
The code that I use to execute the stored procedure is here:
try
{
conn = new SqlConnection("Server=icc-server;DataBase=kennel;Integrated
Security=SSPI");
if (cnKennel.State != ConnectionState.Open)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand("InsertAnimal-info", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@owner_id_1", txtOid.Text));
cmd.Parameters.Add(new SqlParameter("@animal_tag_id_2", txtAnimalTag.Text));
cmd.Parameters.Add(new SqlParameter("@animal_implanted_id_3",
txtAnimalImpId.Text));
cmd.Parameters.Add(new SqlParameter("@sp_nu_4", cbSpNu.Text));
cmd.Parameters.Add(new SqlParameter("@pet_name_5",txtAnimalName.Text));
cmd.Parameters.Add(new SqlParameter("@pet_type_6", cbAnimalType.Text));
cmd.Parameters.Add(new SqlParameter("@pet_breed_7",cbAnimalBreed.Text));
cmd.Parameters.Add(new SqlParameter("@pet_sex_8", cbAnimalSex.Text));
cmd.Parameters.Add(new SqlParameter("@pet_weight_9", txtAnimalWeight.Text));
cmd.Parameters.Add(new SqlParameter("@pet_size_10", cbAnimalSize.Text));
cmd.Parameters.Add(new SqlParameter("@pet_color_11", txtAnimalColor.Text));
cmd.Parameters.Add(new SqlParameter("@pet_age_years_12",
txtAnimalAgeYears.Text));
cmd.Parameters.Add(new SqlParameter("@pet_age_months_13",
txtAnimalAgeMonths.Text));
cmd.Parameters.Add(new SqlParameter("@rate_14",
Convert.ToDecimal(cbRate.Text)));
cmd.Parameters.Add(new SqlParameter("@rate_type_15", cbRateType.Text));
cmd.Parameters.Add(new SqlParameter("@compatable_16", cbCompatable.Text));
cmd.Parameters.Add(new SqlParameter("@medical_condition_17",
txtAnimalMedicalCondition.Text));
cmd.Parameters.Add(new SqlParameter("@pet_location_18",
txtAnimalLocation.Text));
cmd.Parameters.Add(new SqlParameter("@pet_photo_19", pcAnimalPhoto.Text));
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Insert Complete. [animal-info] " + conn +
" Successful.","");
}
rdr.Close();
IdentityValue = Convert.ToInt32(cmd.ExecuteScalar());
osave = IdentityValue.ToString();