Problem with Insert Statement....

M

Manuel Canas

Hello there,

This is my SQL Insert Statement to insert a single into a table on a
database;

INSERT tb_test VALUES(' & _
txtTest1.Text & "' " & _
txtTest2.Text & "' " & _
txtPrice.Text & "')"

Now when I execute this code against the data provider I got and error
saying that I should use the Convert Function on the column "Price", because
of course, the Price on the SQL MSDE is of money type.

I have tried this to try to convert from varchar to money, but no luck.
Dim us As New CultureInfo("en-US")
CType((txtPrice.Text), Decimal).ToString("c", us)

Anybody out there to guide me or give a hint on how to solve this issue?

Thanks very much for your help on this one.

Manny
 
M

Manuel Canas

Hi William,

Thanks for responding to my post. This the final SQL Statement that is going
back to the db.

strSQL = "INSERT tb_product VALUES ('" & _

txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

When you say parameters, how can I implement those?

Thanks for response.

Manny.
 
J

Jon Skeet [C# MVP]

Manuel Canas said:
Thanks for responding to my post. This the final SQL Statement that is going
back to the db.

strSQL = "INSERT tb_product VALUES ('" & _

txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

I think William meant *after* the variables have been put in.
cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

When you say parameters, how can I implement those?

Look up SqlCommand.Parameters in MSDN. I would second William's
recommendation to use them.
 

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