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
|