Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I'm implementing an asp.net c# web site and i'm using this code in order to reduce the
correct quantity of a product when the user press the button finish (or checkout)
"----------------------------------"
C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
       string aSQL = "UPDATE products set quantity=quantity-" + Request.QueryString["quant"] + "Where Id=" + Request.QueryString["Id"];
       try
       {
           con.Open();
           SqlCommand cmd = new SqlCommand(aSQL, con);
           SqlDataReader reader = cmd.ExecuteReader();
           reader.Read();
           DataTable dataTable = new DataTable();
           dataTable.Load(reader);
       }
       finally
       {
           con.Close();
       }

"-----------------------------------"
my issue that it reduces the quantity from the correct product but always (x2)
i can't understand why ? this is a very strange problem,
any help to fix this issue i will be grateful or any other relative solution to use?

thnx in advance!
Jason
Posted
Updated 25-Sep-13 6:27am
v3
Comments
Sergey Alexandrovich Kryukov 25-Sep-13 12:12pm    
Not clear what you are talking about. What quantity? Why reducing correct quantity? What's the problem?
—SA
JasonTsoum77 25-Sep-13 12:22pm    
well here is the whole project i have a shopping cart (cart.aspx) where i collect the products for selling when the customer push the button finish i redirect to another form (finish.aspx) where the customer choose the pay method and the (product quantity must be reduced).
My problem is I import the code that i post in finish.aspx and for some reason the product quantity reduces two times , for example if the customer select quantity 2 in my database it reduces quantity 4.
It is very strange problem and i haven't see anything else like this...thnx for your resoinse
mgoad99 25-Sep-13 14:02pm    
At first glace, it sounds like the code you have to reduce the quantitiy runs twice. Have you tried setting a break point or some other debugging technique?
JasonTsoum77 26-Sep-13 8:10am    
yes i have tried because i suspend something like that but all the variables had the correct values.
I tried the following solution from Karn Singh and that solved the problem.
It was very strange problem because when i tried it seperetally my code worked properly.

Thnx for your response

try this
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
       string aSQL = "UPDATE products set quantity=quantity-1" + Request.QueryString["quant"] + "Where Id=" + Request.QueryString["Id"];


or

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
       string aSQL = "UPDATE products set quantity=--quantity" + Request.QueryString["quant"] + "Where Id=" + Request.QueryString["Id"];

the first one is working i have same project library management where after issuing a book i have to reduce quantity by bookid.try and let me know
 
Share this answer
 
Comments
JasonTsoum77 26-Sep-13 3:03am    
It works!!!! thank you very much Karn for your help and your response!!!
Salman Ali Shah 14-Jul-14 20:03pm    
Jason. R you using any textbox?
Jason. R you using any textbox?
 
Share this answer
 
Comments
[no name] 14-Jul-14 20:08pm    
What possible difference could it make? Do you think that in the past year, the OP has managed to finish his homework assignment? And how would this be a solution anyway?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900