Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m making an application on windows form using c# and sql is the database.
i wanna do this
Quantity = Quantity + q_var
where
Quantity is a database column and q_var is a variable

i know how to use sql UPDATE command. but tell me how can i perform that airthmetic operation?
Posted
Comments
thatraja 20-Jun-11 1:58am    
Show your code

just use dataset and sqladdapter

DataRow dRow = ds1.Tables["table name"].Rows[row number];

variable a = dRow.ItemArray.GetValue(column number).ToString();

Quantity = Quantity + q_var

a = a+q_var...
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:16am    
Sweety Khan might need how to perform that arithmetic operation in UPDATE command
Look at this example : suppose table name Emp contains one column that is EmpId of int type.


in C# code :
declare variable of column type exist in DB

int I=20;

create connection from C# to SQl server and pass this query from the C#:


select EmpId + I from Emp,

u will find the Result.
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:17am    
Sweety Khan might need how to perform that arithmetic operation in UPDATE command.
Sweety Khan 21-Jun-11 11:56am    
sangunni is right but bc of lack of time i dont studied n do this through what i know
i first bring the value from database.
then add it to the variable
n in then send it back to the database means i use one select command n one update
why don't you try this in a store procedure???
 
Share this answer
 
Comments
[no name] 21-Jun-11 9:17am    
That is a good thought, since Sweety Khan need something to perform arithmetic operation in UPDATE
[no name] 22-Jun-11 0:56am    
use CTE (common table expression Query )
SQL
DECLARE @tmpTable as Table (Quantity INT)
INSERT INTO @tmpTable (Quantity) VALUES (100)
SELECT * FROM @tmpTable
UPDATE @tmpTable SET Quantity =Quantity +100
SELECT * FROM @tmpTable



Result Before update:100
Result After update:200
 
Share this answer
 
v3
If you Google it, you might find some ways to do it.
 
Share this answer
 

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