'Add items to db'
Function recordOrder()
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
objDT = Session("Cart")
Dim intCounter As Integer
Dim con2 As New System.Data.OleDb.OleDbConnection
Dim myPath2 As String
myPath2 = Server.MapPath("faraxday.mdb")
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath2 & ";"
Dim myCommand2 As New System.Data.OleDb.OleDbCommand
Dim sql As String
myCommand2.Connection = con2
con2.Open()
'variables'
Dim order_date As String
Dim coupon_ID As String
Dim customer_id As String
Dim quantity As String
'variables'
Try
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
order_date = System.DateTime.Now.Date
coupon_ID = objDR("ID")
quantity = objDR("quantity")
myCommand2.Parameters.Add("@order_date", SqlDbType.VarChar).Value = order_date
myCommand2.Parameters.Add("@coupon_ID", SqlDbType.VarChar).Value = coupon_ID
myCommand2.Parameters.Add("@customer_id", SqlDbType.VarChar).Value = custID
myCommand2.Parameters.Add("@quantity", SqlDbType.VarChar).Value = quantity
myCommand2.CommandText = "INSERT INTO orders(order_date, coupon_id, customer_id, quantity) VALUES (@order_date ,@coupon_ID,@customer_id,@quantity)"
myCommand2.ExecuteNonQuery()
Next
Catch ex As Exception
Finally
If con2.State = ConnectionState.Open Then
con2.Close()
End If
End Try
End Function
循環不增量(intCounter)。請幫助...循環不增加ASP.NET VB
仍然沒有循環... – Farax 2011-04-11 03:54:44
你確定你有多個記錄嗎?你確定沒有錯誤被吞噬嗎?我注意到你的try/catch塊只是將任何異常拋出。也許你可以在這個異常處理程序上進行擴展,看看結果如何? – 2011-04-11 04:09:15
這是拋出的異常:System.NullReferenceException:未將對象引用設置爲對象的實例。 – Farax 2011-04-11 04:13:53