Issue with Update String....

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
 
J

Jared

"WHERE ProductID = @cProductID)"

you forgot to open your where

"WHERE (ProductID = @cProductID)"
 
K

Ken Tucker [MVP]

Hi,

Try this.

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

Ken
-------------------
 
M

Manuel Canas

Hi Ken, No luck with what you suggested.

Do you have anymore suggestions on this one?

Thanks for your help.

Manny.
 
K

Ken Tucker [MVP]

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
 
T

Tarren

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top