Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. :: problem in use UPDATE statement ::

:: problem in use UPDATE statement ::

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasehelpannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nazila Naderi
    wrote on last edited by
    #1

    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 tell me the right string that i can use.

    H K 2 Replies Last reply
    0
    • N Nazila Naderi

      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 tell me the right string that i can use.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      I don't understand your question. Are you asking how to add (or concatenate) two values, or how to execute the UPDATE statement? As far as adding or concatenating values, what you typed works fine so long as the field and intvariable are of the same type or are convertable to the same type. To execute the statement for an Access database, look at the System.Data.OleDb namespace, specifically OleDbConnection, OleDbCommand, and OleDbParameter. Using parameters in your statement makes it easy to execute a statement multiple times by only changing the values of parameters and executing the statement, and saves you from having to do string concatenation (very inefficient if you just use +) and proper quoting and escaping.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      • N Nazila Naderi

        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 tell me the right string that i can use.

        K Offline
        K Offline
        KevinMac
        wrote on last edited by
        #3

        Nazila I thought I might give you a different twist on your question. I write classes that overloaded the toString()'s (if I am being lazy I make them methods) so that I can always get my variables back with the correctly. Example public class AccessDb { //in my data object public int pInt(int intIn) // This is the lazy way {// this is only an example I would use inherited base classes and // overloading the toString it is so much cleaner. return "'" + intIn.toString() + "'" } } // then later in your Business object code AccessDB db = new AccessDb(); db.Update("update table set field=" + db.pInt(intvariable)+ "where otherfield=yes"); I started doing this so I don't get caught recoding everytime the database gets switched from Access to MySql or something else happens. I really like insulating the data objects from the business objects and this is a big help in making generic interfaces. My applications can switch database backends by setting preferences which makes my life much better. It is very important to read up on your database access in .Net and get your design down solid first you will need this when you are setting up the data classes. There are a couple of really cool articles on how to implement this. Let me know what you think of the idea. Kevin

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups