我正在开发一个在线购物网站..当用户将任何商品添加到购物车时,我将其存储在一个表格中...现在我想要的是计算购物车中的商品数量以及更新每次用户添加新项目时,购物车中的商品数量....
请帮助我......我是asp.net的新手。
Public Function AddToCart(ByVal itemID As String, ByVal itemName As String, ByVal itemPrice As Integer, _
ByVal offer As String, ByVal buyNo As String, ByVal userID As String) As String
Dim sqlStatement As String = "INSERT INTO shoppingCart" & _
"(buyNo, userID, itemID, itemName, itemPrice, offer, itemQtty)" & _
"VALUES('" & buyNo & "','" & userID & "','" & itemID & "','" & itemName & "'," & itemPrice & ",'" & offer & "'," & _
"1)"
Dim connStr As String = ConfigurationManager.ConnectionStrings("databaseConnectionString").ConnectionString
Dim con As New SqlClient.SqlConnection(connStr)
'Dim con As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;" & _
' "AttachDbFilename=|DataDirectory|\database.mdf;" & _
' "Integrated Security=True;User Instance=True")
Dim sql As New SqlClient.SqlCommand(sqlStatement, con)
con.Open()
sql.ExecuteNonQuery()
con.Close()
con.Dispose()
MsgBox("Item with 'Item ID: " & itemID & "' & 'Item Name: " & itemName & _
"' has been added to the cart!")
Dim sno As Integer = CType(Replace(buyNo, userID, ""), Integer)
sno = sno + 1
buyNo = userID & sno
Return buyNo
End Function
答案 0 :(得分:2)
我想你在编程方面很新,但每个人都会在某个时候开始。
IF 你正在使用任何类型的数据库来备份你的后端,你可以这样做:
select sum(item_quantity) from user_shopping_cart
为您提供用户购物车中的商品数量。