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. how to use subtract operation in windows form applicaion

how to use subtract operation in windows form applicaion

Scheduled Pinned Locked Moved C#
databasesql-serversysadmintutorialannouncement
7 Posts 4 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.
  • S Offline
    S Offline
    sri apple
    wrote on last edited by
    #1

    i am using this command in sql server it is executed.... /** update product set quantity= quantity - 10 where productname='sugar' ****/ but how to use same command in windows form app... please give me any idea about this..

    P L K 3 Replies Last reply
    0
    • S sri apple

      i am using this command in sql server it is executed.... /** update product set quantity= quantity - 10 where productname='sugar' ****/ but how to use same command in windows form app... please give me any idea about this..

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Use a SqlCommand for the actual sql text, and use a SqlConnection for the connection to the database. A simple search will reveal millions of hits on these topics. You need to use the ExecuteNonQuery method for your command.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      L 1 Reply Last reply
      0
      • S sri apple

        i am using this command in sql server it is executed.... /** update product set quantity= quantity - 10 where productname='sugar' ****/ but how to use same command in windows form app... please give me any idea about this..

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can downvote Pete's answer, but that doesn't make it less correct. It's a very basic piece of work, and there's an copy/paste example in the documentation. If that's too complex, then start studying.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • P Pete OHanlon

          Use a SqlCommand for the actual sql text, and use a SqlConnection for the connection to the database. A simple search will reveal millions of hits on these topics. You need to use the ExecuteNonQuery method for your command.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          +5

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          P 1 Reply Last reply
          0
          • L Lost User

            +5

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Univote countered.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            L 1 Reply Last reply
            0
            • P Pete OHanlon

              Univote countered.

              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Pete O'Hanlon wrote:

              Univote countered.

              Once again.

              1 Reply Last reply
              0
              • S sri apple

                i am using this command in sql server it is executed.... /** update product set quantity= quantity - 10 where productname='sugar' ****/ but how to use same command in windows form app... please give me any idea about this..

                K Offline
                K Offline
                KiranKumar Roy
                wrote on last edited by
                #7

                Dear, May be you need something like below code..

                protected void UpdateData()
                {
                int intQuantity = 0;
                SqlConnection con = new SqlConnection("Your Connectionstring here");
                SqlCommand cmd = new SqlCommand("update product set quantity=@Quantity where productname=@Product", con); ;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@Quantity", intQuantity - 10);
                cmd.Parameters.AddWithValue("@Product", "Sugar");
                cmd.ExecuteNonQuery();
                }

                KiranKumar Roy

                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