| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 596 人关注过本帖
标题:[求助]shopping cart的问题
取消只看楼主 加入收藏
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
 问题点数:0 回复次数:5 
[求助]shopping cart的问题

我想说能否按了confirm button后,cart里所有的资料都能存入database(access)里,这有可能实现吗?
我做过但只能将textbox里的资料存入而不是cart里的资料。
搜索更多相关主题的帖子: cart shopping 
2007-05-03 20:27
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
回复:(wcchyau)[求助]shopping cart的问题
这是cart的code:

Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow

Private Sub Page_Load(s As Object, e As EventArgs)
If Not IsPostBack Then
makeCart()
End If
End Sub

Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
Session("Cart") = objDT
End Function

Sub AddToCart(s As Object, e As EventArgs)
objDT = Session("Cart")
objDR = objDT.NewRow
objDR("Quantity") = txtQuantity.Text
objDR("Product") = txtProduct.Text
objDT.Rows.Add(objDR)
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
End Sub

Sub Delete_Item(s As Object, e As DataGridCommandEventArgs)
objDT = Session("Cart")
objDT.Rows(e.Item.ItemIndex).Delete()
Session("Cart") = objDT
dg.DataSource = objDT
dg.DataBind()
End Sub
2007-05-03 20:29
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
Sub AddRecord(ByVal Sender As Object, ByVal E As EventArgs)
objDT = Session("Cart")
objDR = objDT.NewRow
objDR("Quantity") = txtQuantity.Text
objDR("Product") = txtProduct.Text
objDT.Rows.Add(objDR)
Session("Cart") = objDT

Dim objConn As New oleDbConnection
Dim sqlCmd as String
Dim objCmd As New OleDbCommand(sqlCmd,objConn)
objConn.C
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Customers.mdb")
sqlCmd = "INSERT INTO product (ID, Categories) VALUES (@ID, @Categories)"
objCmd = New OleDbCommand(sqlCmd, objConn)
objCmd.Parameters.Add("@ID",objDR("Quantity"))
objCmd.Parameters.Add("@Categories", objDR("Product"))

objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
End Sub

这是我confirm button的code,我也知道这样子做的话只会存入textbox里的资料,所以想问问该怎么才能存入cart里所有的资料。
2007-05-03 20:29
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
没人帮忙吗?
我从一个网站上看到大概是这样。
for (int x = 0; x < objDT.Rows.Count; x++) {
string sql = "INSERT INTO product (ID, Categories) VALUES ('" + objDT.Rows[x]["Quantity"].ToString() + "', '" + objDT.Rows[x]["Product"].ToString() + "')";

// execute sql here
}

但这是c#的,当我换去vb时就有error了,我该怎么做呢?
for x = 0 to objDT.Rows.Count
sqlCmd = "INSERT INTO product (ID, Categories) VALUES ( @ID , @Categories )"
objCmd = New OleDbCommand(sqlCmd, objConn)
objCmd.Parameters.Add("@ID",objDT.Rows[x]["Quantity"].ToString())
objCmd.Parameters.Add("@Categories", objDT.Rows[x]["Product"].ToString())

Compiler Error Message: BC32017: Comma, ')', or a valid expression continuation expected.
2007-05-04 20:15
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
这就是我全部的操作代码:
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow

Private Sub Page_Load(s As Object, e As EventArgs)
If Not IsPostBack Then
makeCart()
End If
End Sub

Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1

objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))

Session("Cart") = objDT
End Function

Sub AddToCart(s As Object, e As EventArgs)

objDT = Session("Cart")
if objDT.rows.Count <3 then
objDR = objDT.NewRow
objDR("Quantity") = txtQuantity.Text
objDR("Product") = txtProduct.Text
objDT.Rows.Add(objDR)
else
Label5.Text = "sorry,you only allow to add three item to the cart at once"
end if
Session("Cart") = objDT

dg.DataSource = objDT
dg.DataBind()

txtQuantity.text = ""
txtProduct.text = ""


End Sub



Sub Delete_Item(s As Object, e As DataGridCommandEventArgs)
objDT = Session("Cart")
objDT.Rows(e.Item.ItemIndex).Delete()
Session("Cart") = objDT

dg.DataSource = objDT
dg.DataBind()


End Sub


Sub AddRecord(ByVal Sender As Object, ByVal E As EventArgs)
Dim objConn As New oleDbConnection
Dim sqlCmd as String
Dim objCmd As New OleDbCommand(sqlCmd,objConn)
Dim x as integer
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;"
objConn.ConnectionString+= "Data Source= " & Server.MapPath("Account.mdb")
objDT = Session("Cart")

for x = 0 to objDT.Rows.Count -1
sqlCmd = "INSERT INTO ordered (Product, Quantity) VALUES ( @Product , @Quantity )"
objCmd = New OleDbCommand(sqlCmd, objConn)
objCmd.Parameters.Add("@Product", objDT.Rows(x)!Product.ToString())
objCmd.Parameters.Add("@Quantity",objDT.Rows(x)!Quantity.ToString())

next
Session("Cart") = objDT
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()


End Sub
2007-05-05 11:15
wcchyau
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-22
收藏
得分:0 
最后修改的版本有执行,但只讲最后一项的item加入,而不能将全部item都加入database里。
比如说我add了三个item在cart里,但当confirm时只有最后一项的item加入database.
2007-05-05 11:18
快速回复:[求助]shopping cart的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023146 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved