#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    1
    Rep Power
    0

    :: problem in UPDATE statement ::


    I want to do something like below(in ASP.NET & C#):

    string strupdate = "UPDATE table SET field = field + intvariable WHERE otherfield = yes";

    but i don't know how i can do (add a variable value to a numerical field in a ACCESS database).

    Please give me the right string.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    80
    Rep Power
    0
    u first get the value of the field by using SELECT
    then u add ur value to it
    then u write with UPDATE

    so u do something like this

    SELECT field FROM table WHERE ....

    then u get a dataset back,
    u put that value in a variable in ur code
    int myVar = myDataSet.Tables[0].Rows[0]
    then you add ur new data to that variable

    thenn u write back using UPDATE TABLE Set Field = " + myVar.ToString();

    ....

    thats one way of doing it

    Kovan,
  4. #3
  5. A mule with a spinning wheel.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Wales
    Posts
    117
    Rep Power
    14
    You have two methods, constructing a SQL seatment at run time by concatinating strings together or, the faster method, is to create a query in Access. Then use the Command and Parameter objects to run it. I much prefere the second option.

    If you are still having problems then post some code and I'll take a gander at it.

IMN logo majestic logo threadwatch logo seochat tools logo