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 November 27th, 2006, 02:11 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checkout Issue

Hi,
I keep receiving the following error "No value given for one or more required parameters. Source Error:


Line 77:
Line 78: dbConnection.Open()
Line 79: dbCommand.ExecuteNonQuery()
Line 80: dbConnection.Close()
Line 81:


Source File: checkout.aspx Line: 79

[OleDbException (0x80040e10): No value given for one or more required
parameters.]" when clicking on the update button to change the quantity of the item within the checkout.

Here's the main code for the file developed in asp.net 1.1 and vb2003. I suspect the issue lies with the passing of the quantity value but I cannot locate the incorrect code. I've tried debugging but no errors found :

<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    ' Insert page code here
    '




        Function DisplayCart() As System.Data.IDataReader

            Dim strConnString As String = ConfigurationSettings.AppSettings.Get("ConnectionS tring")
            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 tblCartItems.intCartitemID, tblCartItems.intProductID, tblMake.strMake, "& _
            "tblProducts.strProductName, tblType.strTypeDetails, tblColour.strColour, tblCartItems.intQuantityOrder, tblCartItems.curSalePrice "& _
            "FROM tblType INNER JOIN ((tblMake INNER JOIN (tblColour INNER JOIN tblProducts ON tblColour.intColourID = tblProducts.intColourID) "& _
            "ON tblMake.intMakeID = tblProducts.intMakeID) INNER JOIN tblCartItems ON tblProducts.intProductID = tblCartItems.intProductID) "& _
            "ON tblType.intTypeID = tblProducts.intTypeID WHERE [tblCartItems].[intCartID] = " & Session("CartID") & " ; "

            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            dbConnection.Open
            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

            Return dataReader
        End Function


        Sub Page_Load
            DGCart.DataSource = DisplayCart()
            DGCart.DataBind()
        End Sub

        Sub dgCart_Edit(sender As Object, e As DataGridCommandEventArgs)
            dgCart.EditItemIndex = e.Item.ItemIndex

            dgCart.Datasource = DisplayCart()
            dgCart.DataBind()

            lblCart.Text = Session("CartID")
            lblCart.visible=True

        End Sub

        Sub dgCart_Cancel(sender As Object, e As DataGridCommandEventArgs)
            dgCart.EditItemIndex = -1

            dgCart.Datasource = DisplayCart()
            dgCart.DataBind()
        End Sub


        Sub dgCart_Update(sender As Object, e As DataGridCommandEventArgs)

            Dim strConnString As String = ConfigurationSettings.AppSettings.Get("ConnectionS tring")
            strConnString = String.Format(strConnString, Server.MapPath("\db\nwguitars.mdb"))
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(strConnString)

            Dim intCartitemID As Integer
            Dim txtQuantity As TextBox
            Dim intQuantity As Integer

            intCartitemID = dgCart.DataKeys(e.Item.ItemIndex)
            txtQuantity = e.Item.FindControl("txtQuantity")
            intQuantity = txtQuantity.Text
            'intQuantity = Convert.ToInt32(txtQuantity.Text)
            'intQuantity = Cint(CType(e.Item.FindControl("txtQuantity"),TextB ox).Text)

            'If Ctype(e.Item.FindControl("txtQuantity"),TextBox).T ext Is Nothing Then
             'If Ctype(e.Item.FindControl("txtQuantity"),TextBox).T ext Is Nothing Then
                'txtQuantity.Text = "Two"
              'End If

            If intQuantity = Nothing Then
                intQuantity = 2
            End If


            lblQuantity.Text = intQuantity
            lblQuantity.visible=True

            Dim strSQL As String = "UPDATE [tblCartItems] SET [intQuantityOrder]=@Quantity WHERE "& _
            "intCartitemID = @intCartitemID"

            Dim dbCommand As New OleDbCommand(strSQL, dbConnection)

            Dim cmd As New OleDbCommand


            With cmd.Parameters:
                .Add(New OleDbParameter("@Quantity", intQuantity))
                .Add(New OleDbParameter("@intCartitemID", intCartitemID))
            End With

            'With cmd.Parameters:
                '.Add(New OleDbParameter("@Quantity", OleDbType.Integer)).Value = intQuantity
                '.Add(New OleDbParameter("@intCartitemID", OleDbType.Integer)).Value = intCartitemID
            'End With


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

            dgCart.EditItemIndex = -1
            dgCart.DataBind()

        End Sub

        Sub dgCart_Delete(sender As Object, e As DataGridCommandEventArgs)

            dgCart.EditItemIndex = e.Item.ItemIndex

            dgCart.EditItemIndex = -1

            dgCart.Datasource = DisplayCart()
            dgCart.DataBind()
        End Sub

</script>
<html>
<head>
    <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script language="JavaScript" type="text/JavaScript">
    </script>
</head>
<body>
    <div id="top">
        <table cellspacing="0" cellpadding="0" width="100%" border="0">
            <tbody>
                <tr>
                    <td>
                        <img alt="North Wales Guitars" src="images/header/header.gif" /></td>
                </tr>
            </tbody>
        </table>
    </div>

    <br />
    <br />
    <form runat="server">
        <div align="center">
            <h2>View Cart
            </h2>
            <asp:DataGrid id="dgCart" runat="server" OnUpdateCommand="dgCart_Update" OnEditCommand="dgCart_Edit" OnCancelCommand="dgCart_Cancel" OnDeleteCommand="dgCart_Delete" AutoGenerateColumns="False" DataKeyField="intCartitemID">
                <Columns>
                    <asp:BoundColumn DataField="intProductID" ReadOnly="True" HeaderText="ProductID"></asp:BoundColumn>
                    <asp:BoundColumn DataField="strMake" ReadOnly="True" HeaderText="Manufacturer"></asp:BoundColumn>
                    <asp:BoundColumn DataField="strProductName" ReadOnly="True" HeaderText="Product Name"></asp:BoundColumn>
                    <asp:BoundColumn DataField="strTypeDetails" ReadOnly="True" HeaderText="Product Type"></asp:BoundColumn>
                    <asp:BoundColumn DataField="strColour" ReadOnly="True" HeaderText="Colour"></asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="Quantity">
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container, "DataItem.intQuantityOrder") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox id="txtQuantity" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.intQuantityOrder") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateColumn>
                    <asp:BoundColumn DataField="curSalePrice" ReadOnly="True" HeaderText="Price"></asp:BoundColumn>
                    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit Quantity"></asp:EditCommandColumn>
                    <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
                </Columns>
            </asp:DataGrid>
            <br />
        </div>
        <br />
        <asp:Label id="lblCart" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label id="lblQuantity" runat="server"></asp:Label>&nbsp;
        <br />
        <div id="bottom" align="center">| <a href="index.aspx">Home</a> | <a href="aboutus.html">About
            Us</a> | <a href="shop.aspx">Shop</a> | <a href="contact.html">Contact Us</a> | <a href="links.html">Links</a> | <a href="feedback.html">Feedback</a> |
        </div>
    </form>
</body>
</html>

Any assistance would be appreciated - thanks

 
Old November 27th, 2006, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there... you are using 2 commands.. and are giving the parameters to the wrong one ;)

        Dim dbCommand As New OleDbCommand(strSQL, dbConnection)
            Dim cmd As New OleDbCommand
            With cmd.Parameters:
                .Add(New OleDbParameter("@Quantity", intQuantity))
                .Add(New OleDbParameter("@intCartitemID", intCartitemID))
            End With
            dbConnection.Open()
            dbCommand.ExecuteNonQuery()
            dbConnection.Close()

HTH

Gonzalo
 
Old November 27th, 2006, 02:25 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Gonzalo

Please could you explain further exactly what you mean.... Which parameter should I refer to ?

Thanks,

 
Old November 27th, 2006, 02:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. you have to add the parameters to dbcommand object, not to cmd object... because you are executing dbcommand, i don't know what are you doing with cmd object...

HTH

Gonzalo
 
Old November 27th, 2006, 03:50 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Gonzalo.

I updated the code as below :

dbCommand.Parameters.Add("@Quantity", intQuantity)
dbCommand.Parameters.Add("@intCartitemID", intCartitemID)

but I now receive the following error :

"Invalid attempt to FieldCount when reader is closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to FieldCount when reader is closed.

Source Error:


Line 111:
Line 112: dgCart.EditItemIndex = -1
Line 113: dgCart.DataBind()
Line 114:
Line 115: End Sub


Here's the updated sub procedure :

 Sub dgCart_Update(sender As Object, e As DataGridCommandEventArgs)

        Dim strConnString As String = ConfigurationSettings.AppSettings.Get("ConnectionS tring")
        strConnString = String.Format(strConnString, Server.MapPath("\db\nwguitars.mdb"))
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(strConnString)

        Dim intCartitemID As Integer
        Dim txtQuantity As TextBox
        Dim intQuantity As Integer

        intCartitemID = dgCart.DataKeys(e.Item.ItemIndex)
        txtQuantity = e.Item.FindControl("txtQuantity")
        intQuantity = txtQuantity.Text

        Dim strSQL As String = "UPDATE [tblCartItems] SET [intQuantityOrder]=@Quantity WHERE "& _
        "intCartitemID = @intCartitemID"

        Dim dbCommand As New OleDbCommand(strSQL, dbConnection)

        Dim cmd As New OleDbCommand

        dbCommand.Parameters.Add("@Quantity", intQuantity)
        dbCommand.Parameters.Add("@intCartitemID", intCartitemID)

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

        dgCart.EditItemIndex = -1
        dgCart.DataBind()

End Sub








Similar Threads
Thread Thread Starter Forum Replies Last Post
TBH integration with Google Checkout? deasoft BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 November 4th, 2008 01:05 PM
C# Chap13, Checkout (Last Exercise) onlinecg BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 February 20th, 2008 05:49 AM
Error in checkout fase paolo70 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 2 September 10th, 2007 09:03 AM
Chapter 8: checkout process mbeppe BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 4 August 10th, 2007 07:59 AM
Checkout Problem rsm42 ASP.NET 1.0 and 1.1 Basics 0 November 11th, 2006 06:29 AM





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