Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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 2nd, 2006, 04:57 PM
Authorized User
 
Join Date: Mar 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13 Shopping Cart

In Checkout.aspx the line below

OrderID = Convert.ToInt32(cmd.ExecuteScalar())

OrderID is always 0 when inserted into table OrderLines

Can anyone please advise.

thanks,
Michael.



 
Old September 11th, 2006, 01:41 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Might be because you haven't debugged and there is an error on p.479 - Evel should have brackets around.i.e. Eval("ProductID", "WroxShopItem.aspx?ProductID={0}")

 
Old October 5th, 2006, 05:43 AM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, I finally found the answer if you are still interested:

you add this to the end of the first INSERT SQL statement: & _
        "SELECT @@IDENTITY AS OrderID;" and it works fine

 
Old October 13th, 2006, 09:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 105
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to DanM
Default

michaelcode,

As noted in this thread - http://p2p.wrox.com/topic.asp?TOPIC_ID=40977 - you might also want to try using

'SELECT SCOPE_IDENTITY() AS OrderID'

as well.

dan

Dan Maharry
Read the feed at http://feeds.feedburner.com/dansarchive
 
Old May 24th, 2007, 06:57 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I'm using VWD 2005 Express with C#.
cmd.CommandText = "INSERT INTO Orders(MemberName,OrderDate,Name,Address,County,Po stCode,Country,Total)" +
                "VALUES (@MemberName,@OrderDate,@Name,@Address,@County,@Po stCode,@Country,@Total)"+"SELECT @@IDENTITY AS OrderID";
It is OK now.

 
Old January 24th, 2010, 05:06 PM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default repeat always firts product (VB)

Hello, I'm trying to adapt the code for the shopping cart to a database in Access instead of SQL Express.

the code is as follows :
Code:
 
Dim OrderID As Integer
Dim strConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Database1.mdb")
Dim mySql As String = "INSERT INTO Orders(OrderDate, Company, Contact, Email, Phone, Address, City, PostCode, Country, Shipment, Notes) " & _
           "VALUES (Now(), @Company, @Contact, @Email, @Phone, @Address, @City, @PostCode, @Country, @Shipment, @Notes)"
   
        Dim cmd As New OleDbCommand(mySql, strConn)
        
        Try
            strConn.Open()

            'cmd.Parameters.AddWithValue("MemberName", User.Identity.Name)
            cmd.Parameters.AddWithValue("Company", txtCompany.Text)
            cmd.Parameters.AddWithValue("Contact", txtContact.Text)
            cmd.Parameters.AddWithValue("Email", txtEmail.Text)
            cmd.Parameters.AddWithValue("Phone", txtPhone.Text)
            cmd.Parameters.AddWithValue("Address", txtAddress.Text)
            cmd.Parameters.AddWithValue("City", txtCountry.Text)
            cmd.Parameters.AddWithValue("PostCode", txtPostCode.Text)
            cmd.Parameters.AddWithValue("Country", txtCountry.Text)
            cmd.Parameters.AddWithValue("Shipment", txtShipment.Text)
            cmd.Parameters.AddWithValue("Notes", txtNote.Text)
         
            cmd.ExecuteNonQuery()    'This executes the first command
            cmd.CommandText = "SELECT @@Identity As OrderID"
            
            OrderID = cmd.ExecuteScalar() 'This Retrieves the OrderID that was created 
           
            cmd.CommandText = "INSERT INTO OrderLines(OrderID, ProductID, ProductName, Quantity, Measure, Package) " & _
             "VALUES (@OrderID, @ProductID, @ProductName, @Quantity, @Measure, @Package)"
            
            cmd.Parameters.Clear()
            cmd.Parameters.AddWithValue("@OrderID", OrderID)
           
            For Each item As CartItem In Profile.Cart.Items
           
                cmd.Parameters.AddWithValue("@ProductID", item.ProductID)
                cmd.Parameters.AddWithValue("@ProductName", item.ProductName)
                cmd.Parameters.AddWithValue("@Quantity", item.Quantity)
                cmd.Parameters.AddWithValue("@Measure", item.Measure)
                cmd.Parameters.AddWithValue("@Package", item.Package)
                
                cmd.ExecuteNonQuery()
            Next
          
            ' clear the cart
            Profile.Cart.Items.Clear()


        Catch ex As Exception
          
            Throw

        Finally
            strConn.Close()

        End Try

work pretty well, the problem is that if I put in the cart (for example) 5 products, he writes in the database 5 times the first product.

What am I doing wrong?
 
Old January 24th, 2010, 05:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Try calling cmd.Parameters.Clear() as the first line in your for loop and see of that makes a difference.

Chers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 25th, 2010, 03:27 AM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks

I tried, but I get the error "OleDBException. No value specified for some required parameters."
 
Old January 25th, 2010, 03:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, take a look here:

http://social.msdn.microsoft.com/for...5-fc726bb62e09

Create the parameters outside the loop, and then set their value using cmd.Parameters.Item(0).Value inside the loop.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 25th, 2010, 03:50 AM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I modified code as follows :

Code:
  For Each item As CartItem In Profile.Cart.Items
                cmd.Parameters.Clear()
                
                cmd.CommandText = "INSERT INTO OrderLines(OrderID, ProductID, ProductName, Quantity, Measure, Package) " & _
             "VALUES (@OrderID, @ProductID, @ProductName, @Quantity, @Measure, @Package)"
     
                cmd.Parameters.AddWithValue("@OrderID", OrderID)
                cmd.Parameters.AddWithValue("@ProductID", item.ProductID)
                cmd.Parameters.AddWithValue("@ProductName", item.ProductName)
                cmd.Parameters.AddWithValue("@Quantity", item.Quantity)
                cmd.Parameters.AddWithValue("@Measure", item.Measure)
                cmd.Parameters.AddWithValue("@Package", item.Package)
                
                cmd.ExecuteNonQuery()
            Next
and seems to work

thanks anyway for the help





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13: shopping cart problem mysecondlove BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 April 9th, 2008 06:48 PM
Chapter 13 Shopping Cart disappears after login bwinklesky BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 June 14th, 2007 12:34 PM
Ch.13 Builing a Shopping Cart seannie BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 7th, 2007 10:11 AM
Shopping Cart Script in Chapter 15 groovybaz PHP How-To 4 June 7th, 2006 08:21 AM





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