Hello,
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
Dim rate As Decimal
Dim maximumAs Decimal
SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
RadioButtonList1.SelectedValue & "')"
SqlDataSource1.Insert()
CREATE TABLE Example(
userName nvarchar(50),
rate decimal(2, 2),
maximum decimal(6, 2),
ticket nchar(1)
)Try dropping the string delimiters (single quotes). Something like;
"INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
RadioButtonList1.SelectedValue & "')"
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hello,
|
| 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
|
|
| Dim rate As Decimal
| Dim maximumAs Decimal
|
|
| SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
| maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
| RadioButtonList1.SelectedValue & "')"
|
|
| SqlDataSource1.Insert()
|
|
| CREATE TABLE Example(
| userName nvarchar(50),
| rate decimal(2, 2),
| maximum decimal(6, 2),
| ticket nchar(1)
| )
||||Hi,
Already tried that. But this time I got the error:
There are fewer columns in the INSERT statement than values specified
in the VALUES clause. The number of values in the VALUES clause must
match the number of columns specified in the INSERT statement.
Dave Patrick wrote:
> Try dropping the string delimiters (single quotes). Something like;
> "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
> RadioButtonList1.SelectedValue & "')"
> --
> Regards,
> Dave Patrick ...Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
> "Dot Net Daddy" wrote:
> | Hello,
> |
> | 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
> |
> |
> | Dim rate As Decimal
> | Dim maximumAs Decimal
> |
> |
> | SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> | maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> | RadioButtonList1.SelectedValue & "')"
> |
> |
> | SqlDataSource1.Insert()
> |
> |
> | CREATE TABLE Example(
> | userName nvarchar(50),
> | rate decimal(2, 2),
> | maximum decimal(6, 2),
> | ticket nchar(1)
> | )
> ||||I'm not dotnet savvy but you might try something to the effect of;
MsgBox SqlDataSource1.InsertCommand
to see the actual SQL being passed.
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hi,
|
| Already tried that. But this time I got the error:
|
| There are fewer columns in the INSERT statement than values specified
| in the VALUES clause. The number of values in the VALUES clause must
| match the number of columns specified in the INSERT statement.|||thank you so much.. that helped..
silly me.. I was passing the logon name to the database, which was
causing the problem..
thanks for your help...
Dot Net Daddy wrote:
> Hi,
> Already tried that. But this time I got the error:
> There are fewer columns in the INSERT statement than values specified
> in the VALUES clause. The number of values in the VALUES clause must
> match the number of columns specified in the INSERT statement.
>
>
> Dave Patrick wrote:
> > Try dropping the string delimiters (single quotes). Something like;
> >
> > "INSERT INTO Example(userName, rate,
> > maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
> > RadioButtonList1.SelectedValue & "')"
> >
> > --
> >
> > Regards,
> >
> > Dave Patrick ...Please no email replies - reply in newsgroup.
> > Microsoft Certified Professional
> > Microsoft MVP [Windows]
> > http://www.microsoft.com/protect
> >
> > "Dot Net Daddy" wrote:
> > | Hello,
> > |
> > | 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
> > |
> > |
> > | Dim rate As Decimal
> > | Dim maximumAs Decimal
> > |
> > |
> > | SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> > | maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> > | RadioButtonList1.SelectedValue & "')"
> > |
> > |
> > | SqlDataSource1.Insert()
> > |
> > |
> > | CREATE TABLE Example(
> > | userName nvarchar(50),
> > | rate decimal(2, 2),
> > | maximum decimal(6, 2),
> > | ticket nchar(1)
> > | )
> > ||||Good to hear. You're welcome.
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| thank you so much.. that helped..
|
| silly me.. I was passing the logon name to the database, which was
| causing the problem..
|
| thanks for your help...|||I see you have found a resolution to your immediate problem but I want to
point out that this code has a serious vulnerability to SQL injection. I
strongly recommend that you use command parameters instead of string
concatenation and perhaps also use only stored procedures so that direct
table permissions are not needed.
Google "SQL injection" find many discussions on the topic.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Dot Net Daddy" <cagriandac@.gmail.com> wrote in message
news:1156041975.673742.64030@.h48g2000cwc.googlegroups.com...
> Hello,
> 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
>
> Dim rate As Decimal
> Dim maximumAs Decimal
>
> SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> RadioButtonList1.SelectedValue & "')"
>
> SqlDataSource1.Insert()
>
> CREATE TABLE Example(
> userName nvarchar(50),
> rate decimal(2, 2),
> maximum decimal(6, 2),
> ticket nchar(1)
> )
>
No comments:
Post a Comment