Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > Visual Web Developer 2005
|
Visual Web Developer 2005 Discuss creating ASP.NET 2.0 sites with Microsoft's Visual Web Developer 2005. If your question is more specific to a piece of code than the Visual tool, see the ASP.NEt 2.0 forums instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2005 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 March 6th, 2007, 03:33 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default getting info from shopping basket into orders

After the user has selected all his items a button must send all the info to the orders table where it will be selected and emailed to the company and client.
the red part give me an error.
Please help.

This is the code in the 'finish' button...

 Protected Sub btnfinish_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnfinish.Click
        ' TODO: Move to component
        ' Insert the order and order lines into the database
        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrin gs("WroxUnitedConnectionString").ConnectionString )
        Dim trans As SqlTransaction = Nothing
        Dim cmd As New SqlCommand()
        Dim OrderID As Integer


        Try
            conn.Open()
            trans = conn.BeginTransaction
            cmd.Connection = conn
            cmd.Transaction = trans
            'cmd.CommandType = Data.CommandType.StoredProcedure

            ' set the order details
            'cmd.CommandText = "usp_OrderAdd"
            ' TODO: by default in beta 1 creating a stored proc doesn't give execute perms
            cmd.CommandText = "INSERT INTO Orders(MemberName, OrderDate, Name, Address, PostCode, Country, Total) " & _
                             "VALUES (@MemberName, @OrderDate, @Name, @Address, @PostCode, @Country, @Total)"
            cmd.Parameters.Add("@MemberName", Data.SqlDbType.VarChar, 50)
            cmd.Parameters.Add("@OrderDate", Data.SqlDbType.DateTime)
            cmd.Parameters.Add("@Name", Data.SqlDbType.VarChar, 50)
            cmd.Parameters.Add("@Address", Data.SqlDbType.VarChar, 255)
            cmd.Parameters.Add("@PostCode", Data.SqlDbType.VarChar, 15)
            cmd.Parameters.Add("@Country", Data.SqlDbType.VarChar, 50)
            cmd.Parameters.Add("@Total", Data.SqlDbType.Money)

            cmd.Parameters("@MemberName").Value = User.Identity.Name
            cmd.Parameters("@OrderDate").Value = DateTime.Now()
            cmd.Parameters("@Name").Value = CType(FindControl("txtName"), TextBox).Text
            cmd.Parameters("@Address").Value = CType(FindControl("txtAddress"), TextBox).Text
            cmd.Parameters("@PostCode").Value = CType(FindControl("txtPostCode"), TextBox).Text
            cmd.Parameters("@Country").Value = CType(FindControl("txtCountry"), TextBox).Text
            cmd.Parameters("@Total").Value = Profile.Cart.Total

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


            ' change the query and parameters for the order lines
            cmd.CommandText = "INSERT INTO OrderLines(OrderID, ProductID, Quantity, Price) " & _
                             "VALUES (@OrderID, @ProductID, @Quantity, @Price)"
            cmd.Parameters.Clear()
            cmd.Parameters.Add("@OrderID", Data.SqlDbType.Int)
            cmd.Parameters.Add("@ProductID", Data.SqlDbType.Int)
            cmd.Parameters.Add("@Quantity", Data.SqlDbType.Int)
            cmd.Parameters.Add("@Price", Data.SqlDbType.Money)
            cmd.Parameters("@OrderID").Value = OrderID

            For Each item As Wrox.Commerce.CartItem In Profile.Cart.Items
                cmd.Parameters("@ProductID").Value = item.ProductID
                cmd.Parameters("@Quantity").Value = item.Quantity
                cmd.Parameters("@Price").Value = item.Price

                cmd.ExecuteNonQuery()
            Next

            ' clear the cart
            Profile.Cart.Items.Clear()

            ' commit the transaction
            trans.Commit()

        Catch ex As Exception
            ' some form of error - rollback the transaction
            ' and rethrow the exception
            ' TODO: log this?
            If trans IsNot Nothing Then
                trans.Rollback()
            End If

            Throw

        Finally conn.Close()

        End Try
    End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
shopping cart-fly to basket in asp.net shanthiniGanesh .NET Framework 2.0 3 August 1st, 2012 01:36 PM
persistent shopping basket and price changes andieje BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 May 3rd, 2009 12:12 PM
Orders Page with GridView chenimen BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:36 AM
total of items in my basket Ashleek007 Classic ASP Basics 1 January 29th, 2004 10:03 AM





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