Hi,
I have wriiten an e-commerce based site using asp.net 1.1,
vb.net and an access
database. On one of the shopping pages I am trying to update the total of the cart
into a table called "Totals" which I can later reference. Within this table there
are two values, the CartID and the total price.
Whilst I can write the CartID to the tblTotal table I'm not able to write the
total. I suspect this is because I'm not referencing the total value correctly.
This total value is calulated by the viewCountsum variable as shown in the sub
procedure below "Sub ComputeSum". What's the easiest way to refer to this in the
UpdateTotal function.
Sample code below of both the Sub ComputeSum and UpdateTotal function :
Code:
Sub ComputeSum(sender As Object, e As DataGridItemEventArgs)
'Ensure dealing with an Item or AlternatingItem
If e.Item.ItemType = ListItemType.Item OR _
e.Item.ItemType = ListItemType.AlternatingItem then
'Define the ViewCount
Dim viewCount as Integer = Amount
'= Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "curSalePrice"))
viewCountSum += viewCount
ElseIf e.Item.ItemType = ListItemType.Footer then
e.Item.Cells(7).Text = "Total: £" & String.Format("{0:F2}",
viewCountSum)
End If
End Sub
Function GetAmount(curSalePrice As Decimal, intQuantity As Decimal)
Amount = curSalePrice * intQuantity
Total =+ Amount
Return Amount
End Function
Function GetTotal()
Return Total
End Function
Function UpdateTotal(ByVal intCartID As Double, ByVal curGrandTotal As Decimal)
As Integer
Dim strConnString As String =
ConfigurationSettings.AppSettings.Get("ConnectionString")
strConnString = String.Format(strConnString,
Server.MapPath("\db\nwguitars.mdb"))
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(strConnString)
Dim queryString As String = "INSERT INTO [tblTotal] ([intCartID] ,
[curGrandTotal]) "& _
VALUES (@intCartID, @curGrandTotal)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_intCartID As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_intCartID.ParameterName = "@intCartID"
dbParam_intCartID.Value = intCartID
dbParam_intCartID.DbType = System.Data.DbType.Double
dbCommand.Parameters.Add(dbParam_intCartID)
Dim dbParam_curGrandTotal As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_curGrandTotal.ParameterName = "@curGrandTotal"
dbParam_curGrandTotal.Value = curGrandTotal
dbParam_curGrandTotal.DbType = System.Data.DbType.Decimal
dbCommand.Parameters.Add(dbParam_curGrandTotal)
Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try
Return rowsAffected
End Function
Thanks