C
charleswesley
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("SQLConnection"))
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("SQLConnection"))
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>
++++++++++++++++++++++++++++++++++++++++++++++
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("SQLConnection"))
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("SQLConnection"))
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>
++++++++++++++++++++++++++++++++++++++++++++++