Issue with Update String....

  • Thread starter Thread starter Manuel Canas
  • Start date Start date
M

Manuel Canas

Hello there,

this is the piece of code that if giving problems right now;

cnSQL = New SqlConnection(ConnectionString)

**** strSQL = "UPDATE tb_product SET (ProductID = @cProductID, Code = @Code,
ServiceName = @ServiceName, Price = @Price " & _

"WHERE ProductID = @cProductID)" ****

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.Parameters.Add("@cProductID", SqlDbType.Int).Value = txtProductID.Text

cmSQL.Parameters.Add("@Code", SqlDbType.Char).Value = txtServiceCode.Text

cmSQL.Parameters.Add("@ServiceName", SqlDbType.Char).Value =
txtServiceName.Text

cmSQL.Parameters.Add("@Price", SqlDbType.Money).Value = txtPrice.Text

Can anybody tell me please why am I getting an general error saying that the
input String is not in the correct format?

Thanks very much,

Manny
 
"WHERE ProductID = @cProductID)"

you forgot to open your where

"WHERE (ProductID = @cProductID)"
 
Hi,

Try this.

strSQL = "UPDATE tb_product SET ProductID = @cProductID, Code = @Code,
ServiceName = @ServiceName, Price = @Price " & _
"WHERE ProductID = @cProductID"

Ken
-------------------
 
Hi Ken, No luck with what you suggested.

Do you have anymore suggestions on this one?

Thanks for your help.

Manny.
 
Hi,

Actually you need a stored procedure to use parameters. Two options
add a stored procedure to the database or manually insert the values in
the sql statement.

Ken
 
Set the SQL String to the cmSQL.CommandText following the declarations of
the Parameters. Pararmeters are allowed in direct SQL statements, but they
must be referenced in the SQL statement in the order in which they are
declared - the naming of the parameters would lead you to believe that this
does not need to be so, but it is.

Syntactically, the statement looks OK. My guess would be that one of your
parameters is empty, and therefore is killing the SQL statement. What is
the error? Run a debug and check out the values of each of the parameters
right before the statement is executed.
 
Back
Top