Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 09:37 AM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Format a field from a querry SQLServer


Hi guys

How can I format a field containing numbers(double) directly from a querry. The database is SQLServer. I need it so I can link the result as the datasource for a MSHFlexGrid control.

Is there an event MSHFelxGrid whet it fills up. Something like OnFill or smth.

Many thanks


Lucian Preda
[email protected]
__________________
Lucian Preda
[email protected]
 
Old March 3rd, 2004, 10:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Maybe change your query to use SQL Server's STR() function to do the formatting?
Quote:
quote:
Syntax
STR ( float_expression [ , length [ , decimal ] ] )

Arguments
float_expression

Is an expression of approximate numeric (float) data type with a decimal point. Do not use a function or subquery as the float_expression in the STR function.

length

Is the total length, including decimal point, sign, digits, and spaces. The default is 10.

decimal

Is the number of places to the right of the decimal point.
 
Old March 5th, 2004, 10:35 AM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks
But the str function converts the value to a string of a fixed length and it returns it containing spaces.
Anyway I managed to work around my problem.


Lucian Preda
[email protected]
 
Old March 5th, 2004, 10:43 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could of course format it in the SQL Query. SQL has many string functions. Doing formatting in your SQL query can be more efficient than doing it in VB. Here is an example of converting a double to string:

SELECT CONVERT(varchar(20), [mynumber]) as mynumber FROM mytable

If you gave us more of an idea of how you are trying to format the double, I could give you a better example.





Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTO FORMAT field mfahmyg Access 2 April 4th, 2008 07:24 AM
SQLserver 2000 vs SQLserver 2005 Express cJeffreywang BOOK: Beginning ASP.NET 2.0 and Databases 0 April 22nd, 2007 09:52 AM
Saving Image to sqlserver 2000 in binary format kvanchi General .NET 1 May 10th, 2005 07:24 AM
How to format a field predal VB How-To 1 September 30th, 2004 06:41 AM
How to format a Date field Niaz SQL Server 2000 2 June 25th, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.