469,935 Members | 1,604 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

aspnet unleashed store

I'm trying to port the asp.net unleashed sample store from SQLServer to
Access. I have it all do, execpt when I try and add something to the cart I
geet this error:

Exception Details: System.InvalidOperationException: OleDbCommand.Prepare
method requires all parameters to have an explicitly set type.

Source Error:

Line 37:
Line 38: Sub btnAdd_Click( s As Object, e As EventArgs )
Line 39: objShoppingCart.Add( intProductID, strProductName, decUnitPrice )
Line 40: BindDataGrid
Line 41: End Sub

Source File:
D:\webcontent\blackpearl\commerce\Usercontrols\Sho ppingCart.ascx Line: 39

Can anyone help?

Here is the vb file:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Collections

Namespace StoreComponents

''''''''''''''''''''''''''''''''''''''''''
' Contains shared methods for retrieving
' cached database data
''''''''''''''''''''''''''''''''''''''''''
Public Class CachedData

Public Shared Function GetCategories() As DataView
If HttpContext.Current.Cache( "Categories" ) Is Nothing Then
HttpContext.Current.Cache( "Categories" ) = GetCategoriesFromDB
End If
Return HttpContext.Current.Cache( "Categories" )
End Function

Public Shared Function GetCategoryDescription( intCategory As Integer ) As
String
If HttpContext.Current.Cache( "Categories" ) Is Nothing Then
HttpContext.Current.Cache( "Categories" ) = GetCategoriesFromDB
End If
Return HttpContext.Current.Cache( "Categories" ).Item( intCategory )(
"Description" )
End Function

Private Shared Function GetCategoriesFromDB() As DataView
Dim strConString As String
Dim conMyData As OleDbConnection
Dim strSelect As String
Dim dadCategories As OleDbDataAdapter
Dim dstCategories As DataSet

strConString = ConfigurationSettings.AppSettings( "connectionString" )
conMyData = New OleDbConnection( strConString )
strSelect = "Select CategoryID,CategoryName,Description From Categories"
dadCategories = New OleDbDataAdapter( strSelect, conMyData )
dstCategories = New DataSet
dadCategories.Fill( dstCategories, "Categories" )
Return dstCategories.Tables( "Categories" ).DefaultView
End Function

Public Shared Function GetProducts( intCategoryIndex As Integer ) As
DataView
Dim intCategoryID As Integer
Dim dvwProducts As DataView

dvwProducts = HttpContext.Current.Cache( "Products" )
If dvwProducts Is Nothing Then
dvwProducts = GetProductsFromDB
HttpContext.Current.Cache( "Products" ) = dvwProducts
End If
If HttpContext.Current.Cache( "Categories" ) Is Nothing Then
HttpContext.Current.Cache( "Categories" ) = GetCategoriesFromDB
End If
intCategoryID = HttpContext.Current.Cache( "Categories" ).Item(
intCategoryIndex )( "CategoryID" )
dvwProducts.RowFilter = "CategoryID=" & intCategoryID
Return dvwProducts
End Function

Public Shared Function GetProductTemplate( intProductID As Integer ) As
String
Dim intProductIndex As Integer

If HttpContext.Current.Cache( "Products" ) Is Nothing Then
HttpContext.Current.Cache( "Products" ) = GetProductsFromDB
End If
HttpContext.Current.Cache( "Products" ).RowFilter = ""
intProductIndex = HttpContext.Current.Cache( "Products" ).Find(
intProductID )
Return HttpContext.Current.Cache( "Products" ).Item(
intProductIndex )( "Template" )
End Function

Public Shared Function GetProductRow( intProductID As Integer ) As
DataRowView
Dim intProductIndex As Integer

If HttpContext.Current.Cache( "Products" ) Is Nothing Then
HttpContext.Current.Cache( "Products" ) = GetProductsFromDB
End If
HttpContext.Current.Cache( "Products" ).RowFilter = ""
intProductIndex = HttpContext.Current.Cache( "Products" ).Find(
intProductID )
Return HttpContext.Current.Cache( "Products" ).Item( intProductIndex )
End Function

Private Shared Function GetProductsFromDB() As DataView
Dim strConString As String
Dim conMyData As OleDbConnection
Dim strSelect As String
Dim dadProducts As OleDbDataAdapter
Dim dstProducts As DataSet

strConString = ConfigurationSettings.AppSettings( "connectionString" )
conMyData = New OleDbConnection( strConString )
strSelect = "Select * From Products"
dadProducts = New OleDbDataAdapter( strSelect, conMyData )
dstProducts = New DataSet
dadProducts.Fill( dstProducts, "Products" )
dstProducts.Tables( "Products" ).DefaultView.Sort = "ProductID"
Return dstProducts.Tables( "Products" ).DefaultView
End Function
End Class

''''''''''''''''''''''''''''''''''''''''''''''''''
' The ProductTemplate class is the base class
' from which all user control product templates derive
'''''''''''''''''''''''''''''''''''''''''''''''''' '''
Public Class ProductTemplate : inherits UserControl
Public ReadOnly Property ProductID As Integer
Get
Return Context.Items( "ProductID" )
End Get
End Property

Public ReadOnly Property ProductName As String
Get
Return Context.Items( "ProductName" )
End Get
End Property

Public ReadOnly Property UnitPrice As Decimal
Get
Return Context.Items( "UnitPrice" )
End Get
End Property

Public ReadOnly Property Product As DataRowView
Get
Return Context.Items( "ProductInfo" )
End Get
End Property
End Class

'''''''''''''''''''''''''''''''''''''''''''
' The shopping cart
'''''''''''''''''''''''''''''''''''''''''''

Public Class ShoppingCart

Private _conCart As OleDbConnection
Private _dadCart As OleDbDataAdapter
Private _dstCart As DataSet
Private _cbCart As OleDbCommandBuilder
Private _guidUserID As GUID

Sub New()
Dim strConString As String
Dim strSelect As String
Dim objCookie As HttpCookie

' Prepare db connection
strConString = ConfigurationSettings.AppSettings( "connectionString" )
_conCart = New OleDbConnection( strConString )

' Check for StoreUserID cookies
objCookie = HttpContext.Current.Request.Cookies( "StoreUserID" )
If objCookie Is Nothing Then
_guidUserID = Guid.NewGuid
objCookie = New HttpCookie( "StoreUserID", _guidUserID.ToString )
objCookie.Expires = DateTime.Now.AddYears( 3 )
HttpContext.Current.Response.Cookies.Add( objCookie )
Else
_guidUserID = New GUID( objCookie.Value )
End If

' Retrieve the shopping cart
strSelect = "Select itemID, userID, ProductID, ProductName, UnitPrice,
Quantity From ShoppingCarts Where userID = @userID"
_dadCart = New OleDbDataAdapter( strSelect, _conCart )
_dadCart.SelectCommand.Parameters.Add( "@userID", _guidUserID )
_dadCart.MissingSchemaAction = MissingSchemaAction.AddWithKey
_cbCart = New OleDbCommandBuilder( _dadCart )
_dstCart = New DataSet
_dadCart.Fill( _dstCart, "Cart" )
End Sub
Public ReadOnly Property Items As DataView
Get
Return _dstCart.Tables( "Cart" ).DefaultView
End Get
End Property

Public Sub Add( ProductID As Integer, ProductName As String, UnitPrice As
Decimal )
Dim blnMatch As Boolean = False
Dim drowItem As DataRow

For each drowItem in _dstCart.Tables( "Cart" ).Rows
If drowItem( "ProductID" ) = ProductID Then
drowItem( "Quantity" ) += 1
blnMatch = True
Exit For
End If
Next
If Not blnMatch Then
drowItem = _dstCart.Tables( "Cart" ).NewRow
drowItem( "UserID" ) = _guidUserID
drowItem( "ProductID" ) = ProductID
drowItem( "ProductName" ) = ProductName
drowItem( "UnitPrice" ) = UnitPrice
drowItem( "Quantity" ) = 1
_dstCart.Tables( "Cart" ).Rows.Add( drowItem )
End If
UpdateCartDB
End Sub

Public Sub Remove( ItemIndex As Integer )
_dstCart.Tables( "Cart" ).Rows( itemIndex ).Delete
UpdateCartDB
End Sub

Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim drowItem As DataRow
Dim decRunningTotal As Decimal

For intCounter = 0 To _dstCart.Tables( "Cart" ).Rows.Count - 1
drowItem = _dstCart.Tables( "Cart" ).Rows( intCounter )
decRunningTotal += ( drowItem( "UnitPrice" ) * drowItem(
"Quantity" ) )
Next
Return decRunningTotal
End Function

Private Sub UpdateCartDB
_dadCart.Update( _dstCart, "Cart" )
'code here to insert items into dbCart


End Sub
End Class

End Namespace
Nov 18 '05 #1
0 971

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Bill Cunningham | last post: by
9 posts views Thread by Bert Szoghy | last post: by
1 post views Thread by pocm | last post: by
1 post views Thread by safiuddin | last post: by
reply views Thread by Paolo | last post: by
18 posts views Thread by moni | last post: by
13 posts views Thread by pocmatos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.