Skip to content
Advertisement

Database Data Types and their equivelants in Windows Forms

I’ve read in forums about people having issues with certain data types when accessing a database from their website and windows forms application. Mostly the decimal, float and datetime data types.

My DB Table, for example, the Orders table consists of the following Columns. Below each column is the datatype I have chosen to use:

UserId     OrderId     OrderDate     InvoiceTotal      PaymentStatus     DeliveryStatus
int        int         datetime      money             bit               bit

My questions are:

  1. Is (in Windows Forms) DateTime.Now() equivelant to datetime (in WebMatrix DB)? If not, why not? And which method would be best to work with the datetime datatype used in WebMatrix DB?

  2. money Data Type: As far as I know, there is no “money” data type in Windows Forms. You can only use Decimal (which makes sense), but I’ve heard of people also using Float? So, which data type should I use in WinForms so that it just works properly with the money datatype in the DB, and how?

I’m asking these questions because in the past I’ve always had precision problems. Sometimes even inaccuracy problems. I’ve read the docs. Tutorials. Articles, etc. But I feel like I’m missing something…

Advertisement

Answer

Firstly, better clear up some confusion:

  1. Windows Forms is a technology built on top of the .NET Framework. When you describe DateTime.Now, you’re discussing types from the base class library, not Windows Forms.

  2. WebMatrix DB, is in fact, Sql Server Compact.

You might not of come across answers through search if you’re making the mistake of confusing tools with the framework itself.

If you need a way to compare .NET data types with Sql data types, it’s worth looking at the MSDN Library Page which discusses this very thing.

For your specific questions:

  1. DateTime can be used with datetime in most scenarios, however Sql Server cannot deal with exceptional date ranges (e.g. < 01/01/1753). I can’t imagine many scenarios you would need to go less than that, but it’s worth a note.

  2. You’re right, there is no money data type in the base class library, the compatible .NET data type is Decimal. Decimal is a fixed-precision data type which means that all values can be represented and stored with a range, whereas Float is an approximate-number data type, and could be prone precision issues.

There are arguments for using both, for both accuracy and performance reasons, it depends what your application is design to do.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement