Click here to Skip to main content
15,073,507 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Table.stock
Item     qty
1        100kg
2        200kg


Table.Sale
item      qty
1        20kg
2        30kg


*Subtract the qty from stock table insert to sale table

What I have tried:

VB
Strcmd = " UPDATE stock SET qty = stock.qty - sales.qty FROM stock INNER JOIN sales ON stock.item = sales.item"
            'Strcmd = " insert into sales (item,qty)values (@item,@qty)"
            conn = New SqlConnection(Strconn)
            cmd = New SqlCommand(Strcmd, conn)
            cmd.Parameters.Add("@item", SqlDbType.VarChar).Value = TextBox1.Text
            cmd.Parameters.Add("@qty", SqlDbType.Int).Value = TextBox2.Text
            conn.Open()
            dr = cmd.ExecuteReader()
Posted
Updated 22-Jan-18 0:54am
v3
Comments
Member 13067646 22-Jan-18 6:37am
   
Please Help me
[no name] 22-Jan-18 6:46am
   
Where is your Item column Comes?Please repost your question with all the details.
Member 13067646 22-Jan-18 6:48am
   
Item(id) i Change
please help me
[no name] 22-Jan-18 7:11am
   
If you want to insert then why are you writting Update statements.Please update your question.
ZurdoDev 22-Jan-18 9:00am
   
What is your question?
[no name] 22-Jan-18 9:41am
   
My question is:If the developer who wants a solution for this question is writing a question for insert and his/her code in the question seems like he/she is trying to update then how can we give a solution
Richard Deeming 23-Jan-18 13:05pm
   
What's the data type of your quantity columns?

If you're trying to subtract the string '20kg' from the string '100kg', that's not going to work.
Member 13067646 24-Jan-18 12:22pm
   
another way?
Richard Deeming 24-Jan-18 14:30pm
   
Are all the values in KG, or do you have a mix of units?
Member 13067646 25-Jan-18 0:00am
   
qty in kg
Richard Deeming 25-Jan-18 14:41pm
   
In that case, you should change your database column to be a number, and do the formatting in the user interface instead.
Member 13067646 23-Jan-18 13:07pm
   
yes correct

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