none
ADO.NET Dataset appending extra zeroes RRS feed

  • Question

  • Hi all,

    I am using a dataset and storing the result in it through the fill method of ODBCDataAdapter. Suppose if the values in my table are as follows :-

    Rate
    3.1
    3.2
    3.4
    3.7

    Now when i get the same into my dataset, it stores it as

    Rate
    3.10
    3.20
    3.40
    3.70

    I know this is fine in ideal scenarios, but in my case its creating issues as it is a VB6 migrated project. There are some logic based on the fact that the values returned from the database will be exactly the same.

    Any help appreciated for sharing the reason behind the above issue.

    Friday, October 15, 2010 7:56 AM

Answers

  • It seems that number is used as decimal,

    Be aware that ODBC is a seldom anymore used provider, why not OleDB (it seems that you use Jet (ms Access) as database.

     


    Success
    Cor
    • Marked as answer by liurong luo Thursday, October 21, 2010 9:47 AM
    Sunday, October 17, 2010 1:32 AM
  • Yes, it would be a decimal datatype in your DataTable, that makes sense. What doesn't make sense is that trailing zero being displayed in the watch window. As I mentioned in my earlier post, this doesn't happen with the SqlDataAdapter and a SQL Server database. As Cor implied, perhaps the problem is because you're using ODBC. You should try to use the OleDbDataAdapter instead and see if that solves the problem.

    But, what really is the crux of your question is "how are you comparing" DataSet values to database values? You said in your first post that you needed to do this because of legacy logic and the trailing zero is causing problems. But, you haven't shown the code you're using for this comparison ... could you post it?


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by liurong luo Thursday, October 21, 2010 9:47 AM
    Monday, October 18, 2010 2:02 PM

All replies

  • It seems that you use Varchar as datatype (or decimal with 2 decimals)

    In my idea is with the now given information no answer possible.

    Show the Net valuetype and the Server DataType.

     


    Success
    Cor
    Friday, October 15, 2010 9:18 AM
  • Hi Cor,

    The datatype of the above stated column is NUMBER(3,1). The problem is that the value in the dataset just after the "ODBCDataAdapter.fill(Dataset)" is with appended zeros.

    Dim ds as DataSet
    Dim cn as new ODBCConnection
    cn.ConnectionString = "......"
    cn.open()
    Dim da as new ODBCDataAdapter("SELECT RATE FROM TABLE1",cn)
    da.fill(ds)
    
    
    Friday, October 15, 2010 10:47 AM
  • How are you displaying the data (or how are you determining that it is not the same as what's in your database)? What is your backend database?

    With SQL Server, using the SqlDbAdapter, the data remains the same ... IOW, 3.1 is still represented as 3.1 in the DataTable, not 3.10.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Sunday, October 17, 2010 12:34 AM
  • It seems that number is used as decimal,

    Be aware that ODBC is a seldom anymore used provider, why not OleDB (it seems that you use Jet (ms Access) as database.

     


    Success
    Cor
    • Marked as answer by liurong luo Thursday, October 21, 2010 9:47 AM
    Sunday, October 17, 2010 1:32 AM
  • Hi Cor,

    The data type is NUMBER(3,1) and i am using ODBC against Oracle Database (11g).

    I am first of all checking the values inside the Dataset in the quick watch window within the visual studio. In that it still appends an extra zero. Then i tried within the code to check the data type of the column. In that it was changed to decimal!!!

    Is there any way to get the exact number from the database?

    Monday, October 18, 2010 10:54 AM
  • Yes, it would be a decimal datatype in your DataTable, that makes sense. What doesn't make sense is that trailing zero being displayed in the watch window. As I mentioned in my earlier post, this doesn't happen with the SqlDataAdapter and a SQL Server database. As Cor implied, perhaps the problem is because you're using ODBC. You should try to use the OleDbDataAdapter instead and see if that solves the problem.

    But, what really is the crux of your question is "how are you comparing" DataSet values to database values? You said in your first post that you needed to do this because of legacy logic and the trailing zero is causing problems. But, you haven't shown the code you're using for this comparison ... could you post it?


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by liurong luo Thursday, October 21, 2010 9:47 AM
    Monday, October 18, 2010 2:02 PM