473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ERROR: Object must implement IConvertible.

I think the problem is with the strPrice variable in the AddToCart()
sub. I've been messing with it all morning and can't seem to figure it
out. Any ideas?

+++++++++++++++++++++++++++++++++++++++++++
+ EXCEPTION +
+++++++++++++++++++++++++++++++++++++++++++

Object must implement IConvertible.
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.InvalidCastException: Object must implement
IConvertible.

Source Error:

Line 56:
Line 57: oConnection.Open()
Line 58: oCommand.ExecuteNonQuery()
Line 59: oConnection.Close()
Line 60: End Sub

+++++++++++++++++++++++++++++++++++++++++++
+ CODE +
+++++++++++++++++++++++++++++++++++++++++++

<script language="VB" runat="server">
Dim strPrice As String

Sub Page_Load(Sender As Object, e As EventArgs)
GetSingleProduct()
If Not IsPostBack Then
ddlQuantity.SelectedIndex = -1
End If
End Sub

Sub GetSingleProduct()
Dim strSQL As String
Dim oConnection As SqlConnection
Dim oCommand As SqlCommand
Dim oReader As SqlDataReader

strSQL = "SELECT [ID], prdName, prdPrice, prdDesc FROM PRODUCT WHERE
[ID]=" & Request("ID")
oConnection = New
SqlConnection(ConfigurationSettings.AppSettings("S QLConnection"))
oCommand = New SqlCommand(strSQL, oConnection)
oConnection.Open()
oReader = oCommand.ExecuteReader()

lblProduct.Text = ""

If oReader.Read
lblProduct.Text &= "<h1>" & oReader("prdName") & "</h1>" &
oReader("prdDesc")
lblPrice.Text = "<p>" & FormatCurrency(oReader("prdPrice")) & "</p>"
strPrice = oReader("prdPrice")
End If

oReader.Close()
oConnection.Close()
End Sub

Sub AddToCart(s As Object, e As EventArgs)
Dim strSQL AS String = "INSERT INTO CART (GUID, product, quantity,
cost) VALUES (@GUID, @product, @quantity, @cost)"
Dim oConnection As New
SqlConnection(ConfigurationSettings.AppSettings("S QLConnection"))
Dim oCommand As New SqlCommand(strSQL, oConnection)

oCommand.Parameters.Add(New SqlParameter("@GUID", SqlDbType.NVarChar))
oCommand.Parameters.Add(New SqlParameter("@product", SqlDbType.Int))
oCommand.Parameters.Add(New SqlParameter("@quantity", SqlDbType.Int))
oCommand.Parameters.Add(New SqlParameter("@cost", SqlDbType.Money))

oCommand.Parameters("@GUID").Value = Session("GUID")
oCommand.Parameters("@product").Value = Request("id")
oCommand.Parameters("@quantity").Value =
ddlQuantity.SelectedItem.Value
oCommand.Parameters("@cost").Value = strPrice

oConnection.Open()
oCommand.ExecuteNonQuery()
oConnection.Close()
End Sub
</script>

++++++++++++++++++++++++++++++++++++++++++++++

Nov 19 '05 #1
4 2130
UPDATE:

+++ Exception

Disallowed implicit conversion from data type nvarchar to data type
money, table 'DB_128959.dbo.CART', column 'cost'. Use the CONVERT
function to run this query.
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: Disallowed
implicit conversion from data type nvarchar to data type money, table
'DB_128959.dbo.CART', column 'cost'. Use the CONVERT function to run
this query.

Source Error:

Line 51:
Line 52: oConnection.Open()
Line 53: oCommand.ExecuteNonQuery()
Line 54: oConnection.Close()
Line 55: End Sub

+++Code

Sub AddToCart(s As Object, e As EventArgs)
Dim strSQL AS String = "INSERT INTO CART (GUID, product, quantity,
cost) VALUES (@GUID, @product, @quantity, @cost)"
Dim oConnection As New
SqlConnection(ConfigurationSettings.AppSettings("S QLConnection"))
Dim oCommand As New SqlCommand(strSQL, oConnection)

oCommand.Parameters.Add("@GUID", Session("GUID"))
oCommand.Parameters.Add("@product", Request("ID"))
oCommand.Parameters.Add("@quantity",ddlQuantity.Se lectedItem.Value)
oCommand.Parameters.Add("@cost", strPrice)

oConnection.Open()
oCommand.ExecuteNonQuery()
oConnection.Close()
End Sub

Nov 19 '05 #2
SOLUTION:

Dim strSQL AS String = "INSERT INTO CART (GUID, product, quantity,
cost) VALUES (@GUID, @product, @quantity, CAST(@cost As Money))"

Nov 19 '05 #3
And I bet you are earning 650 a day writing e-commerce applications for some
blue chip ??

LOL
<ch***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I think the problem is with the strPrice variable in the AddToCart()
sub. I've been messing with it all morning and can't seem to figure it
out. Any ideas?

+++++++++++++++++++++++++++++++++++++++++++
+ EXCEPTION +
+++++++++++++++++++++++++++++++++++++++++++

Object must implement IConvertible.
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.InvalidCastException: Object must implement
IConvertible.

Source Error:

Line 56:
Line 57: oConnection.Open()
Line 58: oCommand.ExecuteNonQuery()
Line 59: oConnection.Close()
Line 60: End Sub

+++++++++++++++++++++++++++++++++++++++++++
+ CODE +
+++++++++++++++++++++++++++++++++++++++++++

<script language="VB" runat="server">
Dim strPrice As String

Sub Page_Load(Sender As Object, e As EventArgs)
GetSingleProduct()
If Not IsPostBack Then
ddlQuantity.SelectedIndex = -1
End If
End Sub

Sub GetSingleProduct()
Dim strSQL As String
Dim oConnection As SqlConnection
Dim oCommand As SqlCommand
Dim oReader As SqlDataReader

strSQL = "SELECT [ID], prdName, prdPrice, prdDesc FROM PRODUCT WHERE
[ID]=" & Request("ID")
oConnection = New
SqlConnection(ConfigurationSettings.AppSettings("S QLConnection"))
oCommand = New SqlCommand(strSQL, oConnection)
oConnection.Open()
oReader = oCommand.ExecuteReader()

lblProduct.Text = ""

If oReader.Read
lblProduct.Text &= "<h1>" & oReader("prdName") & "</h1>" &
oReader("prdDesc")
lblPrice.Text = "<p>" & FormatCurrency(oReader("prdPrice")) & "</p>"
strPrice = oReader("prdPrice")
End If

oReader.Close()
oConnection.Close()
End Sub

Sub AddToCart(s As Object, e As EventArgs)
Dim strSQL AS String = "INSERT INTO CART (GUID, product, quantity,
cost) VALUES (@GUID, @product, @quantity, @cost)"
Dim oConnection As New
SqlConnection(ConfigurationSettings.AppSettings("S QLConnection"))
Dim oCommand As New SqlCommand(strSQL, oConnection)

oCommand.Parameters.Add(New SqlParameter("@GUID", SqlDbType.NVarChar))
oCommand.Parameters.Add(New SqlParameter("@product", SqlDbType.Int))
oCommand.Parameters.Add(New SqlParameter("@quantity", SqlDbType.Int))
oCommand.Parameters.Add(New SqlParameter("@cost", SqlDbType.Money))

oCommand.Parameters("@GUID").Value = Session("GUID")
oCommand.Parameters("@product").Value = Request("id")
oCommand.Parameters("@quantity").Value =
ddlQuantity.SelectedItem.Value
oCommand.Parameters("@cost").Value = strPrice

oConnection.Open()
oCommand.ExecuteNonQuery()
oConnection.Close()
End Sub
</script>

++++++++++++++++++++++++++++++++++++++++++++++

Nov 19 '05 #4
yeah thats exactly it.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leon Shaw | last post by:
Please help me understand this Error??? Server Error in '/solo' Application. ---------------------------------------------------------------------------- ---- Object must implement...
7
by: Leon Shaw | last post by:
Need help understanding? Server Error in '/solo' Application. ---------------------------------------------------------------------------- ---- Object must implement IConvertible....
5
by: Leon Shaw | last post by:
I'm trying to insert a record into a sql server 2000 database using a store procedure (vs.net is my develop tool) on the button click event but I keep getting the following error after clicking the...
1
by: George Durzi | last post by:
I want to convert a dataset to type object so I can pass it to a generalized function which accepts an object and adds it to the cache. If I pass it in like: Convert.ChangeType(MyDataSet,...
1
by: Tim::.. | last post by:
Hi can someone please help me with the following error! I keep getting: ERROR: System.InvalidCastException: Object must implement IConvertible. Line 231: PageID =...
1
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. My program inserts new rows in a SQL table based on data read from a file. I generated the commands and the stored procedures with the DataAdapter...
3
by: dan | last post by:
I am using VB.NET 2003 and SQL Server 2000. My program inserts new rows in a SQL table based on data read from a file. I generated the commands and the stored procedures with the DataAdapter...
0
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error??? I can't seem to see what is causing the problem... Any help would be greatly appritiated! Thanks ...
0
by: dan | last post by:
Hi, I've been using a GridView for some time but this is the first time I need to delete a row in the grid whose primary key consists of 2 fields (table columns). I have a table with primary...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.