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 February 9th, 2007, 05:07 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Variable Query

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




 
Old February 10th, 2007, 01:05 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed now - thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variable to Query dalezjc Classic ASP Databases 2 November 14th, 2006 03:27 PM
Passing a Variable LarryS Beginning PHP 1 August 8th, 2006 07:52 AM
passing variable tbekarov ASP.NET 2.0 Professional 7 February 1st, 2006 04:16 PM
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM
Passing a variable trekmp ADO.NET 1 March 4th, 2004 01:57 PM





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