|
-
Oct 18th, 2012, 06:26 AM
#1
Thread Starter
Addicted Member
how to change the value of one column in each row ?
i am using C# for windows application and sql server 2005.
create table employeetable(id int not null primarykey, name varchar(100), salary float);
now i have an interface which is used to insert values to this table
id name salary
101 Girmay 350
102 Gech 250
103 Mele 400
104 Rahwa 140
now i want to increase the salary of all the employee in my table by any folds...
for example if i can change it the salary two fold.. i can make a sql statment like this
select salary*2 as newsalary from employeetable. this works fine.. but it is only temporary just to display only.
now i have a textbox and a button.
i want to input any number in the textbox so that it will update each row by multiplying the current salary with the number in the textbox.
so how can i do this?
-
Oct 18th, 2012, 06:48 AM
#2
Re: how to change the value of one column in each row ?
A SELECT statement is for retrieving data. If you want to update data you use an UPDATE statement, e.g.
sql Code:
UPDATE Employee SET Salary = Salary * 2
You would create a SqlCommand containing that SQL code and call its ExecuteNonQuery method. That will do all the work on the database itself, so there's no need to retrieve anything.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|