I had created a shopping cart website using visual studio 2005 web developer
I got this error when i doing update the shopping cart, can anyone please help me solve this problem thanks very much -
Dim cn As New SqlClient.SqlConnection()
-
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ConnectionString
-
-
Dim ProductId As String
-
ProductId = Session("PI")
-
Dim userID As String
-
userID = User.Identity.Name()
-
-
Dim sql As String
-
sql = "SELECT * FROM [Order] WHERE [UserId] = @userID AND [ProductId] = @ProductId "
-
-
Dim cmd1 As New SqlCommand(sql, cn)
-
cmd1.Parameters.AddWithValue("UserId", userID)
-
cmd1.Parameters.AddWithValue("ProductId", ProductId)
-
-
cn.Open()
-
Dim dr As SqlDataReader
-
dr = cmd1.ExecuteReader
-
dr.Read()
-
-
If dr.Read() Then
-
-
sql = "UPDATE [Order] SET Quantity=@Quantity , SubTotal=@SubTotal" & _
-
"WHERE ProductId=@ProductId" & _
-
"AND UserId=@UserId"
-
-
Dim cmd2 As New SqlCommand(sql, cn)
-
-
cmd2.Parameters.AddWithValue("@Quantity", Session("Quantity"))
-
cmd2.Parameters.AddWithValue("@ProductId", ProductId)
-
cmd2.Parameters.AddWithValue("UserId", userID)
-
cmd2.Parameters.AddWithValue("@SubTotal", Session("Price"))
-
cmd2.ExecuteNonQuery()
-
-
-
Else
-
-
sql = "INSERT INTO Order " & _
-
"(UserId, SubTotal, Price, OrderDate, ProductId,Quantity) " & _
-
"VALUES (@UserId, @SubTotal, @Price,@OrderDate, @ProductId,@Quantity)"
-
Dim cmd3 As New SqlCommand(sql, cn)
-
cmd3.Parameters.AddWithValue("@OrderDate", FormatDateTime(Today, DateFormat.LongDate))
-
cmd3.Parameters.AddWithValue("@Price", Session("Price"))
-
cmd3.Parameters.AddWithValue("@SubTotal", Session("Price"))
-
cmd3.Parameters.AddWithValue("@Quantity", Session("Quantity"))
-
cmd3.Parameters.AddWithValue("@ProductId", ProductId)
-
cmd3.Parameters.AddWithValue("UserId", userID)
-
cmd3.ExecuteNonQuery()
-
-
-
End If
-
cn.Close()
-
cmd1.Dispose()
-
cn.Dispose()
-
-
End If
1 1659 jhardman 3,406
Recognized Expert Specialist
which line gives the error?
By the way, this is ASP.NET, not "classic" ASP, right?
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Grant |
last post by:
Hi,
I keep getting the following error message:
InvalidOperationException: There is already an open DataReader associated
with this Connection which must be closed first.
I have read up about it and realise that you can only have one DataReader
open on a Connection at a time, but don't know how to rewrite my code to work
properly.
|
by: fniles |
last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader.
As I read data from tblA, I want to populate tblB. I use SQLDataReader for
both tables. I do not use thread.
When I ExecuteReader on tblB, I get the error "There is already an open
DataReader associated with this Connection which must be closed first."
How can I fix this error ?
For each...
|
by: jimmy |
last post by:
Hi again,
sorry for posting two questions so close together but im working on a
school project which is due in soon and running into some difficulties
implementing the database parts. I have the code below which when
executed generates the following error message: 'There is already an
open datareader with this command which must be closed...
|
by: Bart |
last post by:
Hi,
i get the error:
"There is already an open DataReader associated with this Command which must
be closed first"
Thanks
Bart
-----------------------------------------
Imports System.Data.sqlclient
|
by: BLUE |
last post by:
I've a TransactionScope in which I select some data and I want to do some
queries for each record retrieved with my select.
I'm using a DataReader and for each record I do factory.CreateCommand() and
then I execute the command, but I get the following exception message:
" There is already an open DataReader associated with this Command which...
| |
by: =?Utf-8?B?QXNhZg==?= |
last post by:
Hello,
I have two Table Adapters that I am storing in a Cache using .NET 2.0 Web
Service and the Database is SQL Server on Windows 2003 IIS6.
Each of the two table adapters has its own Connection string.
The reason that table adapters are in cache is because I would like to
maintain the connection string that will not be closed for any...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |