|
 |
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|

September 2nd, 2006, 04:57 PM
|
Authorized User
|
|
Join Date: Mar 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

September 11th, 2006, 01:41 AM
|
Registered User
|
|
Join Date: Aug 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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}")
|

October 5th, 2006, 05:43 AM
|
Registered User
|
|
Join Date: Aug 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 24th, 2007, 06:57 PM
|
Registered User
|
|
Join Date: May 2007
Location: Beijing, , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

January 24th, 2010, 04:06 PM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

January 24th, 2010, 04:50 PM
|
 |
Wrox Author
Points: 71,540, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,998
Thanks: 79
Thanked 1,572 Times in 1,549 Posts
|
|
Hi there,
Try calling cmd.Parameters.Clear() as the first line in your for loop and see of that makes a difference.
Chers,
Imar
|

January 25th, 2010, 02:27 AM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks
I tried, but I get the error "OleDBException. No value specified for some required parameters." 
|

January 25th, 2010, 02:32 AM
|
 |
Wrox Author
Points: 71,540, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,998
Thanks: 79
Thanked 1,572 Times in 1,549 Posts
|
|
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
|

January 25th, 2010, 02:50 AM
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |