Solved

Pulling sql server float as string and keep decimal places

Posted on 2006-11-21
6
2,014 Views
Last Modified: 2008-01-09
Hi Experts,
   I have a sqlserver 2000 table that stores several float fields, in vb.net 03' I am pulling these values via sqldatareader.  My question is how can preserve the value stored as is from the table.  Everyway I have tried, truncates decimals on whole numbers.  I would like to pull these values as is with no rounding or truncation. eg if 75.00 is stored in the db I want to pull 75.00 not 75.  I know I can manually cast these values as varchar in sql to get the values or or do codebehind to handle it, but I'm sure there is a way that I can to pull it from the sqldatareader functions as is.  Thanks in advance ....

oh here is an example just in case:

If qdb.queryDbase(sqlState, sqlConn, reader, False, errText, pnErr) Then
            If reader.HasRows Then
                If reader.Read Then
                    ReDim Preserve cspppdInfo(0)
                    cspppdInfo(0) = reader.GetValue(0)
                End If
            Else
                pnNoRecords.Visible = True
                pnContainer.Visible = False
            End If
End if
0
Comment
Question by:dbedoo
  • 3
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17995043
The only way that I can think that the decimals get truncated are if the field is treated as an integer, instead of a float.

Bob
0
 
LVL 1

Author Comment

by:dbedoo
ID: 17995146
No its treated as a float but VB just doesn't show the decimal point on whole numbers when pulling this way.    I messed it with it for awhile yesterday and couldn't find a way so I ended up using vb code to handle it.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17995163
What happens if you do this?

cspppdInfo(0) = reader("field1").ToString()

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18131587
Delete/No Refund

Bob
0
 
LVL 1

Author Comment

by:dbedoo
ID: 18188616
sorry for the delay ;-)  thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now