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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Decimal field format problem

Decimal field format problem

Scheduled Pinned Locked Moved Database
tutorialdatabasehelpquestionannouncement
5 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.
  • B Offline
    B Offline
    Branislav Vidovic
    wrote on last edited by
    #1

    Hy! I have problem enetring data from my application to the database datable. Basicly this is the table in MS Access 2003 desgin: table name: details table fields: acountNum (Text, primary key) itemId (Integer, primary key) price(Decimal, format: 0,000) quantity(Long integer) The problem is when i use my insert method which has a line that goes like this:

    komanda.CommandText = "INSERT INTO details(acountNum, itemId, price, quantity) VALUES ('" + par1 + "', " + par2 + ", " + par3 + ", " + par4 + ")";

    I use step by stet debuging in studio and check that all the values are correct. But what happens is a problem on a third field of the table. It is formated to represent data in 0,000. That means if you enetr just 3 it wil show like 3,000 in the database. Or if you enetr 2,98 it will show as 2,980 etc.. So let us say that in above comand i pased in these values for variables that store values: par1 = "98bg", par2 = 12, par3 = 4.7 and part4 = 10. When you execute this command in step by step debuger and check the CommandText property it will look like this:

    komanda.CommandText = "INSERT INTO details(acountNum, itemId, price, quantity) VALUES ('98bg', 12, 4,700, 10)";

    We see that the command (which has its connection field already set to a opened connection prior to this) immediatly applied the format rule of price field and turned 4.7 into 4,700. Now of course when i execute the DataAdapter.Update method it will thorow an exception because now we have only 4 fields to insert values and actually 5 values ('98bg', 12, 4,700, 10). 4.7 became 4,700. Of course if i remove the format for the price field in my databse the command works perfectly. But in this situation i ned to have this format of numbers for the price. Does anyone have an idea how to over come this small problem? Cheers!

    E 1 Reply Last reply
    0
    • B Branislav Vidovic

      Hy! I have problem enetring data from my application to the database datable. Basicly this is the table in MS Access 2003 desgin: table name: details table fields: acountNum (Text, primary key) itemId (Integer, primary key) price(Decimal, format: 0,000) quantity(Long integer) The problem is when i use my insert method which has a line that goes like this:

      komanda.CommandText = "INSERT INTO details(acountNum, itemId, price, quantity) VALUES ('" + par1 + "', " + par2 + ", " + par3 + ", " + par4 + ")";

      I use step by stet debuging in studio and check that all the values are correct. But what happens is a problem on a third field of the table. It is formated to represent data in 0,000. That means if you enetr just 3 it wil show like 3,000 in the database. Or if you enetr 2,98 it will show as 2,980 etc.. So let us say that in above comand i pased in these values for variables that store values: par1 = "98bg", par2 = 12, par3 = 4.7 and part4 = 10. When you execute this command in step by step debuger and check the CommandText property it will look like this:

      komanda.CommandText = "INSERT INTO details(acountNum, itemId, price, quantity) VALUES ('98bg', 12, 4,700, 10)";

      We see that the command (which has its connection field already set to a opened connection prior to this) immediatly applied the format rule of price field and turned 4.7 into 4,700. Now of course when i execute the DataAdapter.Update method it will thorow an exception because now we have only 4 fields to insert values and actually 5 values ('98bg', 12, 4,700, 10). 4.7 became 4,700. Of course if i remove the format for the price field in my databse the command works perfectly. But in this situation i ned to have this format of numbers for the price. Does anyone have an idea how to over come this small problem? Cheers!

      E Offline
      E Offline
      Enver Maroshi
      wrote on last edited by
      #2

      I think parameters are working with ms access, this would remove all you troubles related to filling inside decimal values, dates, etc... mostly on computers that have different culture set. Parameters protect you also from sql injection. Or you could use culture info to get decimal seperator and do a replace on string. And i would write variable names on english, it has many benefits. More on parameters here[^]. Edit: You can also write decimal number inside this way ...12, '4,700', 10... But as i wrote, how do you know what is decimal seperator? Different culture, dufferent decimal seperator. Just use parameters.

      B 1 Reply Last reply
      0
      • E Enver Maroshi

        I think parameters are working with ms access, this would remove all you troubles related to filling inside decimal values, dates, etc... mostly on computers that have different culture set. Parameters protect you also from sql injection. Or you could use culture info to get decimal seperator and do a replace on string. And i would write variable names on english, it has many benefits. More on parameters here[^]. Edit: You can also write decimal number inside this way ...12, '4,700', 10... But as i wrote, how do you know what is decimal seperator? Different culture, dufferent decimal seperator. Just use parameters.

        B Offline
        B Offline
        Branislav Vidovic
        wrote on last edited by
        #3

        Thank you! That was helpfull!

        E 1 Reply Last reply
        0
        • B Branislav Vidovic

          Thank you! That was helpfull!

          E Offline
          E Offline
          Enver Maroshi
          wrote on last edited by
          #4

          Moramo si susjedi međusobno pomagat :)

          B 1 Reply Last reply
          0
          • E Enver Maroshi

            Moramo si susjedi međusobno pomagat :)

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            Well,this is english portal. :thumbsup:


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            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