 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 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
|
|
|
|

January 24th, 2010, 05:09 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
repeat always first product in shopping cart (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 25th, 2010, 01:49 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
|
|
I hope someone who knows more about your situation stops by. However... if they don't, I've found that the best way to work with an Access database it using the SQL Server providers (not Access or OleDb). You need to use Access's custom JET 4.0 SQL for your INSERT, UPDATE, SELECT, and DELETE statements, but otherwise I've had very good success and have a lot of experience running websites on shared hosting with limited resources that way.
__________________
-------------------------
Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe
When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper
Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
|
|

January 26th, 2010, 08:32 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
|
|
Can you details for use the entries you are trying to make and the actual entries recorded please?
One would assume that the line
Code:
For Each item As CartItem In Profile.Cart.Items
is the one causing the error.
I haven't used access for some time now but always found it best to write the lines to be reated to a screen to see the real data before enabling the insert lines.
__________________
Try our latest project www.nobanx.com Currency Exchange for members
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| VB shopping cart datalist ch13 |
Alexi |
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 |
2 |
October 3rd, 2006 02:34 AM |
| Shopping Cart |
inkrajesh |
ASP.NET 1.0 and 1.1 Basics |
2 |
February 28th, 2006 03:08 AM |
| shopping cart |
xipnl |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
1 |
June 10th, 2005 07:00 PM |
| shopping cart |
isheikh |
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 |
2 |
October 8th, 2004 04:20 PM |
|
 |