English 中文(简体)
一些数据使用的正确数据类型是什么
原标题:What is the correct data type to use for a number

我是2007年MS Access的新版本,我正在利用2010年视频演播室C#制作申请。 我想知道,在我创建的每个参数中,我应使用何种数据类型。

例如:

command.Parameters.Add(new OleDbParameter("?company_name", OleDbType.VarChar));

这是性质的数据类型(如果我错的话,我就予以更正)。

我的问题是,数字数据类型(实例: zip代码和电话号码(221-0019))在使用 数字数据类型方面是正确的?

P.S.:我已在MS Access上桌。

最佳回答

无论何种数据类型都符合您的数据。

例如,如果需要一栏在0至100之间储存整数,则使用<代码>DataType的外地代码,并附<代码>的外地/代码>。 总数在0到10 000之间<代码>。 1 000 000 000 000 000至1 000 000 000 000 000 000 000 000美元使用Single。 见MSAcess帮助DataType FieldSize,以了解适合您的数据。

然后,在从C#操纵数据库时,使用相应的<代码>OleDbType。 见<代码>OldDbType的帮助,决定其中哪些与MSAccess栏的数据类型相当。

E.g. (按以上实例计算)OleDbType. UnsignTinyInt,OleDbType.SmallInt ,OleDbType.Single

问题回答

在将数据价值作为数字或特性时,需要考虑几个问题。 你们应当了解下列问题。

  1. What will you do if someone decides to enter non numeric characters in the zip or telephone number? dealing with the above example, you will need to remove all non numeric characters for a phone number like (222) 221-0019. The better solution would be to scrub the data before entering it into the database, but storing it as a character can still have its perks.
  2. Sorting. Please note that ordering characters vs numbers can produce some undesired results. note that the numbers 1, 11, and 2 are sorted differently alphabetically vs numerically. Sorted alpha, the correct order is 1, 11, 2. Numerically, they are sorted as 1, 2, 11. This is a consideration when deciding to store a data value as a number or a character field.
  3. Space. Storing these as an integer will take 4 bytes. If you store them as a character, this will take 5 bytes for a 5 digit zip, 10 if using unicode. You probably wont save an astronomical amount of space, all things considered, so 1 and 2 should be bigger considerations.

数据库是储存数据。 你们应当真正思考所储存的价值观的意图。 典型的情况是,如果是实际数字数值,则你只想把物品储存在数量上,如果这些数值是你预期会有数字操作的。 例如,货币、年龄、就业年数。

关于通常所有数字的识别资料,例如社会保障号码、街道号码、电话号码,这些真实数字完全是固定的。 它们是“理论”价值,只是使用数字。 你想把它们储存为特征的原因是,如果你预期主要从事基于特性的业务,那么,在将其从数据库中投放时,你将不得不从数字到特性价值中不断处理。

权衡利弊。 Good Luck!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...