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 10th, 2007, 01:04 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Value error

Hi,

I've written the following code to display the total of a shopping basket based on

its CartID. However when I run the page the total displays as zero even though the

database has a value. I thought intially this may have been an issue with the SQL

statement, so I produced it in Access and imported into my file but not

difference. Any ideas why this is failing, which is written in asp.net 1.1and

vb.net, thanks ?

Code:
 Function GetTotal() As Decimal
        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 = "SELECT tblTotal.intCartID, 

tblTotal.curGrandTotal "& _
        "FROM tblTotal WHERE (((tblTotal.intCartID)=5800310022007))"

        Dim dbCommand As System.Data.IDbCommand = New 

System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open
        dbCommand.ExecuteNonQuery()
        dbConnection.Close()
    End Function


    Sub Page_Load
        lblCart.Text = 5800310022007
        lblTotal.Text = "£ " & GetTotal()
   End Sub

 
Old February 10th, 2007, 06:23 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

rsm42: You are miss-using the functionality of a "Function". Every statement between the Functon declaritive statement and the End Function statement should be in the Page_Load subroutine. In fact the GetTotal function is a non-value added procedure.

Because you are using the SELECT Command, you need to change the "ExecuteNonQuery" to "ExecuteQuery". I would also use the SELECT * FROM tblTotal.

Hope this helps.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





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