G
Guest
I am trying use the following code to update sql. The problem is it only
works once, then I get a message that the '@Param1' can only be used once. I
need to know how to reuse these things or reset them!! Can any one please
help me, you see I am new to this type of code.
try
{
sqlInsertCommand1.CommandText = "INSERT INTO services([service-code],
[service-description], [large-animal-cost], [medium-animal-cost],
[small-animal-cost]) " values(@Param1,@Param2,@Param3, @Param4,@Param5)";
SqlParameter param =
sqlInsertCommand1.Parameters.Add("@Param1",SqlDbType.Int);
param.Value = txtServiceCode.Text;
param = sqlInsertCommand1.Parameters.Add("@Param2",SqlDbType.VarChar);
param.Value = txtServiceDesc.Text;
param = sqlInsertCommand1.Parameters.Add("@Param3",SqlDbType.Money);
param.Value = Convert.ToDecimal(cbLargeAnimalCost.Text);
param = sqlInsertCommand1.Parameters.Add("@Param4",SqlDbType.Money);
param.Value = Convert.ToDecimal(cbMediumAnimalCost.Text);
param = sqlInsertCommand1.Parameters.Add("@Param5",SqlDbType.Money);
param.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.","");
}
works once, then I get a message that the '@Param1' can only be used once. I
need to know how to reuse these things or reset them!! Can any one please
help me, you see I am new to this type of code.
try
{
sqlInsertCommand1.CommandText = "INSERT INTO services([service-code],
[service-description], [large-animal-cost], [medium-animal-cost],
[small-animal-cost]) " values(@Param1,@Param2,@Param3, @Param4,@Param5)";
SqlParameter param =
sqlInsertCommand1.Parameters.Add("@Param1",SqlDbType.Int);
param.Value = txtServiceCode.Text;
param = sqlInsertCommand1.Parameters.Add("@Param2",SqlDbType.VarChar);
param.Value = txtServiceDesc.Text;
param = sqlInsertCommand1.Parameters.Add("@Param3",SqlDbType.Money);
param.Value = Convert.ToDecimal(cbLargeAnimalCost.Text);
param = sqlInsertCommand1.Parameters.Add("@Param4",SqlDbType.Money);
param.Value = Convert.ToDecimal(cbMediumAnimalCost.Text);
param = sqlInsertCommand1.Parameters.Add("@Param5",SqlDbType.Money);
param.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.","");
}