|
Posted by Erland Sommarskog on 08/20/06 09:45
Dot Net Daddy (cagriandac@gmail.com) writes:
> I cannot get the following Insert Command work. I get the error:
>
>
> Error converting data type varchar to numeric.
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.Data.SqlClient.SqlException: Error converting
> data type varchar to numeric.
>
> However 'rate' and 'maximum' variables are declared as Decimal
In VB, yes. SQL does not read VB declarations.
> Dim rate As Decimal
> Dim maximumAs Decimal
>
> SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> RadioButtonList1.SelectedValue & "')"
In you constructed SQL command, you put the values of rate and
maximum in single quotes. Why would you express decimal values as
character literals?
Anyway, the correct way to do this is to use parameterised command,
just as David said. I have an example at
http://www.sommarskog.se/dynamic_sql.html#queryplans. (You need to
scroll a bit down to get the VB .Net example.)
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|