Results 1 to 2 of 2

Thread: how to change the value of one column in each row ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width