Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is been a month i am working on inventory management system using c#, it has stock managment to so we can add items that how much we have in our hand but when i sell it from purchase form how to cut down its quantity from database.
Sorry for my bad english.

What I have tried:

I tried to select item quantity from database and -1 items and then insert it to database again but i am sure this is not the right way
Posted
Updated 9-Mar-16 7:00am
Comments
CHill60 9-Mar-16 12:29pm    
Just update directly on the database. Share the code you used
Kho Dam 9-Mar-16 12:55pm    
//Click Button1 Even Code
int quantity=0;
int quantityInHand=0;
mycon.open();
SqlCommand cmd = new SqlCommand("SELECT Quantity FROM ITEMS WHERE NAME1='"+txtproductname.Text+"'" , mycon);
SqlDataReader reader = cmd.ExecuteReader();
quantity = int.Parse.reader["Quantity"];
quantityInHand = quantity - int.Parse(txtquantity.Text);
SqlCommand cmd2 = new SqlCommand("INSER INTO ITEMS (Quantity) Values("quantityInHand") WHERE NAME1='"+txtproductname.Text+"';" , mycon);
cmd2.ExecuteNonQuery();
mycon.close();

1 solution

To update the quantity, just run an UPDATE sql statement. Very simple:
SQL
UPDATE products
SET quantity = quantity - 1
WHERE product_id = @product_id
 
Share this answer
 
Comments
Kho Dam 9-Mar-16 13:08pm    
UPDATE products
SET quantity = quantity - 1
WHERE product_id = @product_id

in this code????

products is table name????
quantity is field????
product_id is product ID number????

right????
ZurdoDev 9-Mar-16 13:22pm    
Yes. Just think of it in simple english (or whatever your native language is. :) )

You want to update the quantity in the database to be 1 less.
Kho Dam 9-Mar-16 13:27pm    
yes i want to update the quantity in the database to be less according my quantity textbox.

can we use it like:
UPDATE products
SET quantity = quantity - convert.int32(txtquantity.text)
WHERE product_id = @product_id
ZurdoDev 9-Mar-16 13:30pm    
Yes, but use a parameter instead so you don't open up your db to security risks.
Kho Dam 9-Mar-16 13:34pm    
Thank you very much indeed.
but we can use this code for selling items,
but how we can make these sells report for every items we less from products table.
like inventory softwares.
Thank You : )

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