By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

VB.NET CStr Function Yields Different Results With SQL Decimal Value

P: n/a
We recently noticed that the vb.net CStr function yields different
results than the vb6 version when converting SQL decimal data. If, for
example, the data is defined in SQL as decimal(19,10), the vb.net CStr
function will return ten digits to the right of the decimal,
regardless of the data value. In this case, if the data value is 5,
the vb.net CStr function will return 5.0000000000. The vb6 CStr
function will simply return 5. In other words, the vb.net CStr
function always returns digits the length of the scale value after the
decimal. The vb6 CStr function will not return the trailing zeroes.
Why?

Thanks, Bill
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Try using ToString() instead. It's inherited from Object. CStr is actually
using the Microsoft.VisualBasic library which may or may not cause problems.
ToString() is the *correct* .NET way to do it (you cuould also use CType,
but ToString just makes it easier in most cases)

HTH,
CJ
"Bill L." <bl****@penson.com> wrote in message
news:50**************************@posting.google.c om...
We recently noticed that the vb.net CStr function yields different
results than the vb6 version when converting SQL decimal data. If, for
example, the data is defined in SQL as decimal(19,10), the vb.net CStr
function will return ten digits to the right of the decimal,
regardless of the data value. In this case, if the data value is 5,
the vb.net CStr function will return 5.0000000000. The vb6 CStr
function will simply return 5. In other words, the vb.net CStr
function always returns digits the length of the scale value after the
decimal. The vb6 CStr function will not return the trailing zeroes.
Why?

Thanks, Bill

Nov 20 '05 #2

P: n/a
"Bill L." <bl****@penson.com> wrote in message
news:50**************************@posting.google.c om...
We recently noticed that the vb.net CStr function yields different
results than the vb6 version when converting SQL decimal data.


Bill,

I gave up on VB4's CStr() function many, /many/ moons ago, being
too lazy to have to thank about the leading space that positive values
are tagged with (reserved for a minus sign on nagative numbers, of
course). I /invariably/ used Format() to convert numbers into Strings
which, in .Net, means <value>.ToString( <format> ).

HTH,
Phill W.
Nov 20 '05 #3

P: n/a
Hi CJ,

I see I am in the opposition toDay.

toString() is the from C languages derived method to do it.

(The only one I use by the way)

Cor


Nov 20 '05 #4

P: n/a
I never said I was 100% correct. =)

BTW, have you read some of the conversations from msmobiles in the
smartphone group.

Now that is some funny stuff. He bashes the EU alot... Not that its funny
he's bashing the EU, but his "evidence" supporting his theories is funny.

=)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ua*************@TK2MSFTNGP11.phx.gbl...
Hi CJ,

I see I am in the opposition toDay.

toString() is the from C languages derived method to do it.

(The only one I use by the way)

Cor

Nov 20 '05 #5

P: n/a
> BTW, have you read some of the conversations from msmobiles in the
smartphone group.

Now that is some funny stuff. He bashes the EU alot... Not that its funny he's bashing the EU, but his "evidence" supporting his theories is funny.

I was looking, however was only suprissed that Bill Vaughn was involved in
that newsgroup for the rest nothing intresting. Did not see that on the EU,
however for me it seems to be a kid.

I wish often the times that especially Nak was doing those things but much
better in this newsgroup where there again.

Cor
Nov 20 '05 #6

P: n/a
* "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> scripsit:
I gave up on VB4's CStr() function many, /many/ moons ago, being
too lazy to have to thank about the leading space that positive values
are tagged with (reserved for a minus sign on nagative numbers, of


I think you are talking about the 'Str' function, not 'CStr'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

P: n/a
* "CJ Taylor" <[cege] at [tavayn] dit commmmm> scripsit:
ToString() is the *correct* .NET way to do it (you cuould also use CType,
but ToString just makes it easier in most cases)


There is no "correct .NET way", there is only personal preference.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

P: n/a
As it turns out, I am able to use ToString instead of CStr if I
explicitly convert the data value to Object using CType(I don't
necessarily know what the data type is being returned from SQL, I'm just
blindly converting to String). Thanks for the suggestion. This is, of
course, preferable.

The behavior is, however, the same. To see for yourself, return from SQL
a value of decimal data type and simply convert it to string.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9

P: n/a
FINE!! JUST F*#(*$@! be that way then!



j/k
=)
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "CJ Taylor" <[cege] at [tavayn] dit commmmm> scripsit:
ToString() is the *correct* .NET way to do it (you cuould also use CType, but ToString just makes it easier in most cases)


There is no "correct .NET way", there is only personal preference.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.