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 September 8th, 2006, 02:31 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating Access Databases

Can anyone help ? I'm trying to update an access database via shopping cart but keep receiving the error
No value given for one or more required parameters. I'm using asp.net 1.1 with vb2003. Can anyone suggest where I'm going wrong - thanks ?


Sub AddToCart(sender As Object, e As EventArgs)

        Dim CartID As Integer
        Dim DateTime As Date
        Dim intProductID As Integer = sender.CommandArgument

        'Create a variable named Now and set it to the current date/time
        Dim Now as DateTime = DateTime.Now
        Dim s as String

        s = Now.ToString("MMM dd, yyyy")

        'Reference our cart
        'objDT = Session("CartID")

        'Create a new row
        objDR = objDT.NewRow
        objDR("CartID") = Session("CartID")
        objDR("ItemID") = intProductID
        objDR("DateTime") = Now.ToString("MMM dd yyyy") & " " & DateTime.Now.ToLongTimeString()

        objDT.Rows.Add(objDR)


        'add DT into session
        Session("Cart") = objDT

        'Bind data
        DGCart.DataSource = objDT
        DGCart.DataBind()


    End Sub

    Sub UpdateDbase(sender As Object, e As EventArgs)

        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand

        Dim cmd as New OleDbCommand

        Dim CartID As Integer
        Dim DateTime As Date
        Dim intProductID As Integer

        With cmd.Parameters:
            .Add(New OleDbParameter("@CartID",CartID))
            .Add(New OleDbParameter("@ProductID",intProductID))
            .Add(New OleDbParameter("@DateTime", Now.ToString("MMM dd yyyy") & DateTime.Now.ToLongTimeString()))
        End With



        Dim myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=F:\db\nwguitars.mdb")

        myConnection.Open()

        Dim myCommand = New OleDbCommand("INSERT INTO [tblCart] VALUES (@CartID,@intProductID,@DateTime)",myConnection)
        myCommand.ExecuteNonQuery()
        myConnection.Close()

    End Sub

 
Old September 8th, 2006, 02:34 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Do you have a key constraint in the table you are inserting to that you are not populating? What line does the error come from? Do all the variables you using to populate your command parameters contain a value?

"The one language all programmers understand is profanity."
 
Old September 9th, 2006, 04:07 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

All fields should be populated with the intCartID value as the primary key. Within the code I have created a datagrid (DGCart) just as a test to ensure the information is being passed when you click on the "Buy" button. I have a datalist set up that display all the products including each product's individual ProductID.

This message appears when you try to update the database. i suspect its becuase there does not seem to be any values to update the database but I'm not sure how to reference them . Thanks,

 
Old September 9th, 2006, 05:34 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

rsm42:

Now() is the name of a vb.net instrinsic function. Assign a different name in the Dim statement and see what happens.

Hope this helps.
 
Old September 11th, 2006, 12:12 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

Changed it but no different - any other ideas , thanks?

 
Old September 11th, 2006, 12:36 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well that makes sense, in your method UpdateDbase you define the variables but do not set the value to anything, thus you are trying to add variables that are null (err Nothing in vb) as your parameters.

To reference the values, if they are the same values that you use in your first method, place them in a session variable.

Dont declare variables with the name DateTime this is a type in VB and should be a reserved keyword. (Use some form of Hungarian notation e.g. iInteger for integers, sString for strings dtDate for datetime values etc.)


"The one language all programmers understand is profanity."
 
Old September 11th, 2006, 12:43 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks

As another test I actually removed the DateTime entry completely and still get this error. I take your point which sounds valid, but suspect the code is not passing the CartID and intProductID variables either - but struggling how to fix this.



 
Old September 11th, 2006, 12:54 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No you dont understand. You are doing this:

        Dim CartID As Integer
        Dim DateTime As Date
        Dim intProductID As Integer

but you never assign values to these variables. You just automatically place them as parameters for your query, so the failure in the data being passed is that you are not passing it in anyway. The above variables literally have a value of null (Nothing), you need to pass values into them.

"The one language all programmers understand is profanity."
 
Old September 11th, 2006, 01:35 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again for the reply.

Just to clarify I already have the data contained within a database and I have created a datalist which references the database and its values and displays the product items. What I am trying to do is to write some code so when a customer clicks on the "AddToCart" button, the values from the datalist are written to the table in the database.

I acknowledge that the current "AddToCart" sub routine is not trying to reference these values, but I'm not sure HOW to actually rectify this in terms of code. If you could offer some sample code that would be excellent.

Here's is my Datalist code for reference :

<asp:datalist id="DataList" runat="server" RepeatColumns="2" RepeatDirection="Horizontal">
                <ItemTemplate>
                    <table cellpadding="5" align="left" border="1">
                        <tr>
                            <td valign="top" width="180" height="140">
                                Product ID: <%# DataBinder.Eval(Container.DataItem, "intProductID") %>
                                <br />
                                <br />
                                Manufacturer: <%# DataBinder.Eval(Container.DataItem, "strMake") %>
                                <br />
                                <br />
                                Product Name: <%# DataBinder.Eval(Container.DataItem, "strProductName") %>
                                <br />
                                <br />
                                Colour: <%# DataBinder.Eval(Container.DataItem, "strColour") %>
                                <br />
                                <br />
                                Quantity In Stock: <%# DataBinder.Eval(Container.DataItem, "IntQuantityInStock") %>
                                <br />
                                <br />
                                Price: <%# DataBinder.Eval(Container.DataItem, "curSalePrice", "{0:c}") %>
                            </td>
                            <td align="center" width="110">
                                <img src='./images/<%# Databinder.Eval(Container.DataItem, "strImage") %>' valign="top" />
                            </td>
                            <td>
                                <asp:Button id="btnBuy" runat="server" Text="Buy" onclick="AddToCart" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "intProductID")%>'></asp:Button>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:datalist>


 
Old September 11th, 2006, 01:44 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In your AddToCart method you could just do: e.commandArgument which will return the value of that products Product ID then you could just grab the information from the database.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Synch 2 access databases raguapk Pro VB 6 2 December 11th, 2007 11:27 PM
Updating databases with VB 2005 Express PatCiferri VB How-To 3 December 3rd, 2007 08:31 AM
MS Access Databases dmoffice VB Databases Basics 1 October 10th, 2006 03:37 PM
Access Databases won't update through code wwwaynes Access ASP 2 October 3rd, 2004 03:33 PM





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