G
Guest
When I try to insert the second record I get the message "The Variable name
"@Parm1" has already been declared. What can I do to prevent this. The code:
try
{
sqlInsertCommand1.CommandText = "INSERT INTO services([service-code],
[service-description]" +
" ,[large-animal-cost], [medium-animal-cost], [small-animal-cost])" +
" values(@Parm1,@Parm2,@Parm3, @Parm4,@Parm5)";
sqlInsertCommand1.Parameters.Add("@Parm1",SqlDbType.Int).Value =
txtServiceCode.Text;
sqlInsertCommand1.Parameters.Add("@Parm2",SqlDbType.VarChar).Value =
txtServiceDesc.Text;
sqlInsertCommand1.Parameters.Add("@Parm3",SqlDbType.Money).Value =
Convert.ToDecimal(cbLargeAnimalCost.Text);
sqlInsertCommand1.Parameters.Add("@Parm4",SqlDbType.Money).Value =
Convert.ToDecimal(cbMediumAnimalCost.Text);
sqlInsertCommand1.Parameters.Add("@Parm5",SqlDbType.Money).Value =
Convert.ToDecimal(cbSmallAnimalCost.Text);
sqlInsertCommand1.Connection = sqlConnection1;
if (sqlConnection1.State != ConnectionState.Open)
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
this.sqlConnection1.Close();
MessageBox.Show("Insert Complete. [services] " + txtServiceNbr.Text +
" Successful.","");
"@Parm1" has already been declared. What can I do to prevent this. The code:
try
{
sqlInsertCommand1.CommandText = "INSERT INTO services([service-code],
[service-description]" +
" ,[large-animal-cost], [medium-animal-cost], [small-animal-cost])" +
" values(@Parm1,@Parm2,@Parm3, @Parm4,@Parm5)";
sqlInsertCommand1.Parameters.Add("@Parm1",SqlDbType.Int).Value =
txtServiceCode.Text;
sqlInsertCommand1.Parameters.Add("@Parm2",SqlDbType.VarChar).Value =
txtServiceDesc.Text;
sqlInsertCommand1.Parameters.Add("@Parm3",SqlDbType.Money).Value =
Convert.ToDecimal(cbLargeAnimalCost.Text);
sqlInsertCommand1.Parameters.Add("@Parm4",SqlDbType.Money).Value =
Convert.ToDecimal(cbMediumAnimalCost.Text);
sqlInsertCommand1.Parameters.Add("@Parm5",SqlDbType.Money).Value =
Convert.ToDecimal(cbSmallAnimalCost.Text);
sqlInsertCommand1.Connection = sqlConnection1;
if (sqlConnection1.State != ConnectionState.Open)
sqlConnection1.Open();
sqlInsertCommand1.ExecuteNonQuery();
this.sqlConnection1.Close();
MessageBox.Show("Insert Complete. [services] " + txtServiceNbr.Text +
" Successful.","");