none
Problem when reading float values using .NET Data Providers RRS feed

  • Question

  • Hi All,

     

    I am facing a problem when accessing the float value from .NET Data Providers. The underlying database has a table with float as column type.I can access the float values which are large from the .NET Data Providers.For example when i use select statement in the sql server management studio(sql server 2005) i can't read the exact float value,but when doing so with either sql server 2000 client or using sqlcmd utility i can read the exact value.When i done some reserch on websites and msdn i found that sqlcmd uses sql native client library which is an OLEDB provider and management studio uses .NET Data Provider.Is there a solution to access the float value as it is from the database using .NET Data Provider.

    Wednesday, July 11, 2007 6:06 PM

All replies

  • Hi Mahesh,

         Did you find any answer ? Please provide me the answer if you found. I am also trying to read exact float value from sql server. But DataReader/DataSet truncating and rounding the final digits. Please answer if anyone knows.

     

    Thanks.

    Friday, July 13, 2007 4:21 PM
  • Are you printing it out with toString without any formatting options?  The conversion of a float to text needs a little care to make sure you don't truncate on print.  You may have the right value, but be losing precision on print.

     

    Hope that helps,

     

    John

    Friday, July 13, 2007 6:48 PM
  • Thanks for the response. I am NOT converting into string variable. I am trying to assign the sql float value into single(or double)  but looks like it is truncating in the provider level.  Please help if anyone know how to retrieve sql float value (say 234.12444499993)  as it is in .NET.

     

    Thanks

    Saturday, July 14, 2007 2:05 PM
  • I didnt find the answer.The problem is in double data type used in .NET.When we use .NET datareader or dataset it binds to the double datatype in .NET . .NET seems to truncate some values.I tried this with managed c++,the managed c++ doesn't truncate any values.The work around i am following now is to use sql_variant datatype in sql server and cast it to float in sql server for any numerical operations and read sql variant as it is.If any one knows how to overcome please suggest.

     

    Thanks,

    Mahesh

    Sunday, July 15, 2007 6:29 PM
  •  Vijay Srinivasan wrote:

    Thanks for the response. I am NOT converting into string variable. I am trying to assign the sql float value into single(or double)  but looks like it is truncating in the provider level.  Please help if anyone know how to retrieve sql float value (say 234.12444499993)  as it is in .NET.

     

    Thanks

     

    Formatting Float is not easy because you cannot set precision and scale in SQL Server, but custom formatting in the FCL(framework class library) covers most if it is coming from SQL Server.  The links below will get you started.  Hope this helps.

     

    http://blogs.msdn.com/kathykam/archive/2006/03/29/net-format-string-101.aspx

    http://msdn2.microsoft.com/en-us/library/7x5bacwt(VS.80).aspx

    Monday, July 16, 2007 1:04 AM
  • Hi,
    I was getting the same error. When I was selecting the float values in sql server using a SELECT statement, I realized that managemnet studio was rounding the float values to display. But when I tried to read the value in a variable and used that variable for the comparison, management studio is not rounding the value. So management studion only rouding the value when it is displaying it. The actual values for the computation remain the same.
    Monday, February 23, 2009 3:42 PM