开发者

What data type to use for some number, date and phone number in c#?

开发者 https://www.devze.com 2023-02-17 17:16 出处:网络
Hi I have an application in asp.net which contains four text fields for number, amount, date and telephone. When clicked on a button these values has to be saved into Oracle Database. Used procedures

Hi I have an application in asp.net which contains four text fields for number, amount, date and telephone. When clicked on a button these values has to be saved into Oracle Database. Used procedures to save these values. In oracle database datatypes are, number column is of type number, amount column is of type number, date column is of type datetime and phonenumber is of type number. I am using validations for all four text fields so that these values are in proper form开发者_高级运维at. In my code I am passing number, date, telephone as string and amount as double. Is this the best pratice ? If not can any one suggest me the data types I have to use for 4 fields (number, amount, date and telephone number) ?


Generally speaking, you should use decimal in C# to represent number fields in a database; use DateTime in C# to represent datetime fields in a DB.

I do not recommend using a number field to store things that only contain digits but aren't actual numbers (like credit card numbers, phone numbers, ZIP codes, and SSNs). A string (varchar) better represents those values.


If it works, it's "good enough" practice. You're not doing this a million times in a loop, so efficiency isn't an issue. What you are doing is clear and understandable and is a good fit for the types of data that you're handling. Date and phone number formats are tricky in editing. Do you have to deal with international dates (much of the world is fond of dd-mm-yy) and non-US phone numbers? I like your data types.


Store the amount (assuming this is monetary) as a number(14,2) or something similar. Don't use a double, as some decimals can't be expressed precisely as a double. In C# use the decimal type, and in Oracle a number type.

See also: Is a double really unsuitable for money?

0

精彩评论

暂无评论...
验证码 换一张
取 消