Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 9th, 2007, 09:32 AM
Authorized User
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update Query

I've been working on an e-commerce web site written in asp.net 1.1 and vb.net. Within the shopping cart I have created a sub procedure that calculates the total of the order , which is called "Sub ComputeSum".

Additionally, within this sub procedure there is some code that allows this total value to be updated if a customer continues shopping and adds more items to their cart and therefore increases the total value. This total value is then updated within a table in an access database.

This code works by checking to see if there are any rows in the table corresponding to that cartID. If not, the total value is inserted into the database. If the cartID already exists, i.e. the customer has updated their existing order, the total value is updated in the database. However this update does not seem to work - any ideas where this may be failing ? Here's the main code from the "Sub ComputeSum" sub procedure - thanks:

 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
             viewCountSum += viewCount
             'Otherwise display total info in footer
            ElseIf e.Item.ItemType = ListItemType.Footer then
              e.Item.Cells(7).Text = "Total: £" & String.Format("{0:F2}", viewCountSum)

               'If no CartID in table = insert data

                 'Define required variables
                 Dim intCartID As Double
                 intCartID = Session("CartID")
                 Dim curGrandTotal As Decimal
                 curGrandTotal = viewCountSum

                 Dim DataSet As DataSet
                 Dim DTable As DataTable
                 Dim loop1, numrows As Integer
                 Dim SessionID = Session("CartID")

                 'SQL statement to look up required data
                 Dim strSQL As String = "SELECT [tblTotal].[intCartID], [tblTotal].[curGrandTotal] FROM [tblTotal] WHERE ([tblTotal].[intCartID]) = " & Session("CartID") & " ; "

                'Create a connection to data source
                 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)

                'Create a command object with SQL statement
                 Dim DAdapter As OleDbDataAdapter
                 DAdapter = New OleDbDataAdapter(strSQL,dbConnection)

                'Fill dataset with data from database
                 DataSet = New System.Data.DataSet

                'Create a new DataTable object and assign to it
                'the new table in the tables collection
                 DTable = New DataTable
                 DTable = DataSet.Tables(0)

                 'Find out how many rows of new DataTable object
                 numrows = DTable.Rows.Count

                 If numrows = 0

                 'If number of rows found = zero then insert total and cartID into table in db
                 Dim queryString As String = "INSERT INTO [tblTotal] ([intCartID] , [curGrandTotal]) " & _
                 "VALUES (@intCartID, @curGrandTotal)"

                 'Define command objects
                 Dim dbComm As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
                 dbComm.CommandText = queryString
                 dbComm.Connection = dbConnection

                 'Define CartID and Total parameters
                 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
                 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

                 'Connect to db and perform query

                 'If CartID already exists = update data

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Query Help dalezjc Classic ASP Basics 8 March 18th, 2008 08:49 AM
I solved insert query.now see this Update Query. amit_mande@yahoo.com VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Update query trab Access 1 May 11th, 2006 03:58 PM
Please Help me about UPDATE query huyremy VB Databases Basics 8 September 29th, 2004 03:45 AM
Update query edcaru Access 3 June 14th, 2004 03:04 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.