SqlMoney for money/smallmoney

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

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
 
Hi Tom,

Casting to decimal is fine. However, SqlMoney does exist in the
System.Data.SqlTypes namespace.
 
Dave Sexton said:
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
http://davesexton.com/blog

tshad said:
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
 
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.

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

tshad said:
Dave Sexton said:
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
http://davesexton.com/blog

tshad said:
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
 
Hi,

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

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

Dave Sexton said:
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.

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

tshad said:
Dave Sexton said:
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
http://davesexton.com/blog

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top