Reputation: 9268
I am new to MS Access 2007 and I am creating an application using Visual Studio 2010 C#. I am wondering what datatype should I use in each parameter I am creating.
For example:
command.Parameters.Add(new OleDbParameter("?company_name", OleDbType.VarChar));
This is a data type for characters(correct me if I am wrong).
My question is, what is the data type for numbers(example: zip code and telephone number(221-0019)) to use is correct to use the numeric data type?
P.S.: I already have my table in MS Access
Upvotes: 3
Views: 4724
Reputation: 29955
Use whatever datatype fits your data.
E.g. if you require a column to store whole number between 0 to 100 use a field with a DataType
of Number
with a FieldSize
of Byte
. For a whole number between 0 and 10,000 use Integer
. For a fractional number between -1,000,000,000 and 1,000,000,000 use Single
. See the MSAcess help for DataType
and FieldSize
to see what is appropriate for your data.
Then, when manipulating the database from C#, use the equivalent OleDbType
. See the help for OldDbType
to decide which one is equivalent to the datatype in the MSAccess column.
E.g. (as per above examples) OleDbType.UnsignedTinyInt
, OleDbType.SmallInt
, OleDbType.Single
Upvotes: 1
Reputation: 641
There are a few things to think about when storing data values as numbers or characters. You should be aware of the following issues.
Databases are about storing data. You should really think about the intention of the values being stored. Typically, you only want to store things as numbers if they are actual numerical values that you would expect to have numerical operations. For example, money, age, number of years employed.
As for identifiers that are typically all numbers, for example social security numbers, street numbers, phone numbers, these really arent numbers at all. They are "character" values that just happen to only use numbers. The reason you would want to store them as characters is that when bringing them in from the database, if you expect to be doing primarily character based operations, you will have to deal with continually casting them from numeric to character values.
Weigh the pros and cons. Good Luck!
Upvotes: 1