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:
Is (in Windows Forms)
DateTime.Now()equivelant todatetime(in WebMatrix DB)? If not, why not? And which method would be best to work with thedatetimedatatype used in WebMatrix DB?moneyData Type: As far as I know, there is no “money” data type in Windows Forms. You can only useDecimal(which makes sense), but I’ve heard of people also usingFloat? So, which data type should I use in WinForms so that it just works properly with themoneydatatype 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:
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.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:
DateTimecan be used withdatetimein 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.You’re right, there is no
moneydata type in the base class library, the compatible .NET data type isDecimal. Decimal is a fixed-precision data type which means that all values can be represented and stored with a range, whereasFloatis 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.