Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SqlMoney for money/smallmoney

0 views
Skip to first unread message

tshad

unread,
Jan 4, 2007, 6:25:10 PM1/4/07
to
I am trying to get some information from Sql Server 2000 in my VS 2003 C#
code.

For example:

if(dbReader["WSFilingStatus"] != DBNull.Value) wsFilingStatus =
(SqlMoney)dbReader["WSFilingStatus"];

This gives me an error that SqlMoney is not a valid type. But in some of
the docs it says this is the one to use. I can't seem to make it work so I
changed it to:

if(dbReader["WSFilingStatus"] != DBNull.Value) wsFilingStatus =
(decimal)dbReader["WSFilingStatus"];

But not sure if this is the best way or not.

Thanks,

Tom

Dave Sexton

unread,
Jan 4, 2007, 8:05:33 PM1/4/07
to
Hi Tom,

Casting to decimal is fine. However, SqlMoney does exist in the
System.Data.SqlTypes namespace.

--
Dave Sexton
http://davesexton.com/blog

"tshad" <tschei...@ftsolutions.com> wrote in message
news:uMJNVeFM...@TK2MSFTNGP03.phx.gbl...

tshad

unread,
Jan 4, 2007, 9:16:24 PM1/4/07
to
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:Od8QbVGM...@TK2MSFTNGP02.phx.gbl...

> Hi Tom,
>
> Casting to decimal is fine. However, SqlMoney does exist in the
> System.Data.SqlTypes namespace.

Then do I need to add a new Using statement? Because I am getting an error
if I specify it.

I already have:

using System;
using System.Data;
using System.IO;
using System.Data.SqlClient;

Thanks,

Tom

Dave Sexton

unread,
Jan 4, 2007, 9:44:33 PM1/4/07
to
Hi,

Yes, you need a new using statement. SqlMoney isn't defined in SqlClient,
it's defined in SqlTypes.

Regardless, decimal is fine unless you require the ability to check for
DBNull, but since you've already hard-coded a check for DBNull, using
SqlMoney would be redundant.

"tshad" <tschei...@ftsolutions.com> wrote in message

news:u3ynA%23GMHH...@TK2MSFTNGP03.phx.gbl...

Dave Sexton

unread,
Jan 4, 2007, 9:55:20 PM1/4/07
to
Hi,

Technically, it's a using directive that you need, not a using statement :)

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:OWpFwMHM...@TK2MSFTNGP04.phx.gbl...

0 new messages