Issue with Update String and Parameters....

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
 
E

Earl

You need to cast your text boxes/strings to integers, i.e.,

Cint(txtProductID.Text)

You may also need to validate that none of those are empty strings.
 
E

EijiTek

From what I can tell the error is occurring on the line that reads:
cmSQL.Parameters.Add("@cProductID", SqlDbType.Int).Value =
txtProductID.Text
and would also occur on the line that reads
cmSQL.Parameters.Add("@Price", SqlDbType.Money).Value = txtPrice.Text

Essentially, you're trying to force a string (txtProductID.Text) into an int
and another string (txtPrice.Text) into a double (the money type in Sql
Server is really a decimal with the precision and scale set). Because there
is no implicit conversion defined for string to any numeric value you'll
need to use the parse method of the appropriate target data type (ie:
Int32.Parse(txtProductID.Text)).

Read the MSDN documentation on the parse methods for more information
including how to parse currency formatted values. I've included a link for
the Int32 parse method:
http://msdn.microsoft.com/library/d...pref/html/frlrfsystemint32classparsetopic.asp
 

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