Problem defining object


G

Guest

I'm converting a C# ASP app to VB.net. I create a shopping cart on this line:

Dim cart As WebApplication3.ShoppingCartDB1 = New
WebApplication3.ShoppingCartDB1

I get the error:

e:\inetpub\wwwroot\WebApplication3\AddToCart.aspx.vb(20): Type
'WebApplication3.ShoppingCartDB1' is not defined.

Thing, is, ShoppingCartDB1 IS defined in the project and saved:

Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Namespace WebApplication3

'*******************************************************
'
' ShoppingCartDB Class
'
' Business/Data Logic Class that encapsulates all data
' logic necessary to add/remove/update/purchase items
' within an IBuySpy shopping cart.
'
'*******************************************************

Public Class ShoppingCartDB

'*******************************************************
'
' ShoppingCartDB.GetItems() Method <a name="GetItems"></a>
'
' The GetItems method returns a struct containing
' a forward-only, read-only DataReader. This displays a list of all
' items within a shopping cart. The SQLDataReaderResult struct
' also returns the SQL connection, which must be explicitly closed
' after the data from the DataReader is bound into the controls.
'
' Other relevant sources:
' + <a href="ShoppingCartList.htm"
style="color:green">ShoppingCartList Stored Procedure</a>
'
'*******************************************************

Public Function GetItems(ByVal cartID As String) As SqlDataReader

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

' Execute the command
myConnection.Open()
Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)

' Return the datareader result
Return result
End Function

'*******************************************************
'
' ShoppingCartDB.AddItem() Method <a name="AddItem"></a>
'
' The AddItem method adds an item into a shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartAddItem.htm"
style="color:green">ShoppingCartAddItem Stored Procedure</a>
'
'*******************************************************

Public Sub AddItem(ByVal cartID As String, ByVal productID As
Integer, ByVal quantity As Integer)

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartAddItem", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterProductID As SqlParameter = New
SqlParameter("@ProductID", SqlDbType.Int, 4)
parameterProductID.Value = productID
myCommand.Parameters.Add(parameterProductID)

Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

Dim parameterQuantity As SqlParameter = New
SqlParameter("@Quantity", SqlDbType.Int, 4)
parameterQuantity.Value = quantity
myCommand.Parameters.Add(parameterQuantity)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub

'*******************************************************
'
' ShoppingCartDB.UpdateItem() Method <a name="UpdateItem"></a>
'
' The UpdateItem method updates the quantity of an item
' in a shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartUpdate.htm"
style="color:green">ShoppingCartUpdate Stored Procedure</a>
'
'*******************************************************

Public Sub UpdateItem(ByVal cartID As String, ByVal productID As
Integer, ByVal quantity As Integer)

' throw an exception if quantity is a negative number
If quantity < 0 Then
Throw New Exception("Quantity cannot be a negative number")
End If

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartUpdate", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterProductID As SqlParameter = New
SqlParameter("@ProductID", SqlDbType.Int, 4)
parameterProductID.Value = productID
myCommand.Parameters.Add(parameterProductID)

Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

Dim parameterQuantity As SqlParameter = New
SqlParameter("@Quantity", SqlDbType.Int, 4)
parameterQuantity.Value = quantity
myCommand.Parameters.Add(parameterQuantity)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub

'*******************************************************
'
' ShoppingCartDB.RemoveItem() Method <a name="RemoveItem"></a>
'
' The RemoveItem method removes an item from a
' shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartRemoveItem.htm"
style="color:green">ShoppingCartRemoveItem Stored Procedure</a>
'
'*******************************************************

Public Sub RemoveItem(ByVal cartID As String, ByVal productID As
Integer)

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartRemoveItem", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterProductID As SqlParameter = New
SqlParameter("@ProductID", SqlDbType.Int, 4)
parameterProductID.Value = productID
myCommand.Parameters.Add(parameterProductID)

Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub

'*******************************************************
'
' ShoppingCartDB.GetItemCount() Method <a name="GetItemCount"></a>
'
' The GetItemCount method returns the number of items
' within a shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartItemCount.htm"
style="color:green">ShoppingCartItemCount Stored Procedure</a>
'
'*******************************************************

Public Function GetItemCount(ByVal cartID As String) As Integer

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartItemCount", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

' Add Parameters to SPROC
Dim parameterItemCount As SqlParameter = New
SqlParameter("@ItemCount", SqlDbType.Int, 4)
parameterItemCount.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterItemCount)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

' Return the ItemCount (obtained as out paramter of SPROC)
Return (CType(parameterItemCount.Value, Integer))
End Function

'*******************************************************
'
' ShoppingCartDB.GetTotal() Method <a name="GetTotal"></a>
'
' The GetTotal method returns the total price of all
' items within the shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartTotal.htm"
style="color:green">ShoppingCartTotal Stored Procedure</a>
'
'*******************************************************

Public Function GetTotal(ByVal cartID As String) As Decimal

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartTotal", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

Dim parameterTotalCost As SqlParameter = New
SqlParameter("@TotalCost", SqlDbType.Money, 8)
parameterTotalCost.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterTotalCost)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

' Return the Total
If parameterTotalCost.Value.ToString() <> "" Then
Return CType(parameterTotalCost.Value, Decimal)
Else
Return 0
End If
End Function

'*******************************************************
'
' ShoppingCartDB.MigrateCart() Method <a name="MigrateCart"></a>
'
' The MigrateCart method migrates the items from one
' cartId to another. This is used during the login
' and/or registration process to transfer a user's
' temporary cart items to a permanent account.
'
' Other relevant sources:
' + <a href="ShoppingCartMigrate.htm"
style="color:green">ShoppingCartMigrate Stored Procedure</a>
'
'*******************************************************

Public Sub MigrateCart(ByVal oldCartId As String, ByVal NewCartId As
String)

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartMigrate", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim cart1 As SqlParameter = New SqlParameter("@OriginalCartId ",
SqlDbType.NVarChar, 50)
cart1.Value = oldCartId
myCommand.Parameters.Add(cart1)

Dim cart2 As SqlParameter = New SqlParameter("@NewCartId ",
SqlDbType.NVarChar, 50)
cart2.Value = NewCartId
myCommand.Parameters.Add(cart2)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub

'*******************************************************
'
' ShoppingCartDB.EmptyCart() Method <a name="EmptyCart"></a>
'
' The EmptyCart method removes all current items within
' the shopping cart.
'
' Other relevant sources:
' + <a href="ShoppingCartEmpty.htm"
style="color:green">ShoppingCartEmpty Stored Procedure</a>
'
'*******************************************************

Public Sub EmptyCart(ByVal cartID As String)

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("ShoppingCartEmpty", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim cartid As SqlParameter = New SqlParameter("@CartID",
SqlDbType.NVarChar, 50)
cartid.Value = cartID
myCommand.Parameters.Add(cartid)

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub

'*******************************************************
'
' ShoppingCartDB.GetShoppingCartId() Method <a
name="GetShoppingCartId"></a>
'
' The GetShoppingCartId method is used to calculate the
' "ShoppingCart" ID key used for a tracking a browser.
'
' The ShoppingCartID value is either the User's Identity
' Name (if they are a registered and authenticated user),
' or a random GUID calculated for guest visitors or
' customers who have not yet logged in.
'
'*******************************************************

Public Function GetShoppingCartId() As String

' Obtain current HttpContext of ASP+ Request
Dim context As System.Web.HttpContext =
System.Web.HttpContext.Current

' If the user is authenticated, use their customerId as a
permanent shopping cart id
If context.User.Identity.Name <> "" Then
Return context.User.Identity.Name
End If

' If user is not authenticated, either fetch (or issue) a new
temporary cartID
If Not context.Request.Cookies("IBuySpy_CartID") Is Nothing Then
Return context.Request.Cookies("IBuySpy_CartID").Value
Else
' Generate a new random GUID using System.Guid Class
Dim tempCartId As Guid = Guid.NewGuid()

' Send tempCartId back to client as a cookie
context.Response.Cookies("IBuySpy_CartID").Value =
tempCartId.ToString()

' Return tempCartId
Return tempCartId.ToString()
End If
End Function
End Class
End Namespace
 
Ad

Advertisements

S

singh_angrez

hi,
i thing WebApplication.ShoppingCartDB is defined not
WebApplication.ShoppingCartDB1

Feel free to tell if i am wrong. just try the following thing:

Dim cart As WebApplication3.ShoppingCartDB­ = New
WebApplication3.ShoppingCartDB­

Regards,
angrez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top