The dream of the second attention

Tuesday, November 22, 2005

Formatting sql numeric values for display in crystal reports

If you are using Crystal Reports that comes with Visual Studio .NET 2003, and you are using the DataSource for the report as a datset, then you must have run into the bug that it only accepts un-typed datasets (an object from System.Dataset). If you try to bind to a typed dataset, you get this wierd schema error. This is all fine still unless you have float values in your table, this will be displayed very strangely in your crystal report (something like 1.2300000000e+03 for a value of 123, which of course looks terrible). Now if you were to use a typed dataset with this column defined as double the problem will be gone, but since you can't, you have to solve this problem on the database level itself. A very useful sql function of code can be found here. To call it in a query, it will look like this select [xNumberFormat]([MyTable].[MyColumn], ''#########.000'') as [MyColumn] from [MyTable]
Happy Programming !!!!

0 Comments:

Post a Comment

<< Home