Home All Groups Group Topic Archive Search About

determine sql decimal precision in .net

Author
19 May 2006 6:09 AM
Sam
Hi,

I would like to be able to read the scale & precision of a decimal type
contained in a sql server table  from vb.net.
I would like to set some properties (like width,format) of a gridview's
field based upon the width (scale,precision) of the database column.

Previously, in VB6 with ADO i was able to do that.
In .Net i can read the dataType, but that returns me a .net decimal and
apparently i cannot read a scale/precision from that.

Any solutions or advise would be greatly appreciated.

As a side question:
we've tried to use our own types in sql server 2000. Apparently these
are just aliasses for the underlying type (e.g.: someAmount =
decimal(6,2)). We've tried reading these types in .Net, but also here we
got a .Net decimal. If we could read our types (the names) then we could
  style the gridview's field accordingly.

Sam.

Author
19 May 2006 7:39 AM
Tasos Vogiatzoglou
You can use the GetSql<type> methods in the SqlDataReader.

e.g.

rdr.GetSqlDecimal(rdr.GetOrdinal("field"));

SqlDecimal struct has the fields you want.

Regards,
Tasos
Are all your drivers up to date? click for free checkup

Author
22 May 2006 9:09 AM
Sam
Tasos Vogiatzoglou wrote:
> You can use the GetSql<type> methods in the SqlDataReader.
>
> e.g.
>
> rdr.GetSqlDecimal(rdr.GetOrdinal("field"));
>
> SqlDecimal struct has the fields you want.
>
> Regards,
> Tasos
>

Thanks Tasos, that was indeed the solution i was looking for.

Sam.

Bookmark and Share