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
{
sqlInsertComman d1.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 =
sqlInsertComman d1.Parameters.A dd("@Param1",Sq lDbType.Int);
param.Value = txtServiceCode. Text;
param = sqlInsertComman d1.Parameters.A dd("@Param2",Sq lDbType.VarChar );
param.Value = txtServiceDesc. Text;
param = sqlInsertComman d1.Parameters.A dd("@Param3",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbLargeAnima lCost.Text);
param = sqlInsertComman d1.Parameters.A dd("@Param4",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbMediumAnim alCost.Text);
param = sqlInsertComman d1.Parameters.A dd("@Param5",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbSmallAnima lCost.Text);
sqlInsertComman d1.Connection = sqlConnection1;
if (sqlConnection1 .State != ConnectionState .Open)
sqlConnection1. Open();
sqlInsertComman d1.ExecuteNonQu ery();
this.sqlConnect ion1.Close();
MessageBox.Show ("Insert Complete. [services] " + txtServiceNbr.T ext +
" Successful.","" );
}
--
Norm Bohana
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
{
sqlInsertComman d1.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 =
sqlInsertComman d1.Parameters.A dd("@Param1",Sq lDbType.Int);
param.Value = txtServiceCode. Text;
param = sqlInsertComman d1.Parameters.A dd("@Param2",Sq lDbType.VarChar );
param.Value = txtServiceDesc. Text;
param = sqlInsertComman d1.Parameters.A dd("@Param3",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbLargeAnima lCost.Text);
param = sqlInsertComman d1.Parameters.A dd("@Param4",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbMediumAnim alCost.Text);
param = sqlInsertComman d1.Parameters.A dd("@Param5",Sq lDbType.Money);
param.Value = Convert.ToDecim al(cbSmallAnima lCost.Text);
sqlInsertComman d1.Connection = sqlConnection1;
if (sqlConnection1 .State != ConnectionState .Open)
sqlConnection1. Open();
sqlInsertComman d1.ExecuteNonQu ery();
this.sqlConnect ion1.Close();
MessageBox.Show ("Insert Complete. [services] " + txtServiceNbr.T ext +
" Successful.","" );
}
--
Norm Bohana
Comment