开发者

help on database in c#

I have an Sql database in my C# program since c# allows you to build database inside the program. The question can an attribute(column) in a database be a range. for example, can I 开发者_开发知识库have attribute for the weight such as one of its values 120-130, so that it's more easy than specifying 10 values.


You could use two columns: Min and Max.

 Name   | Min | Max
--------------------
 Item 1 | 120 | 130
          ...


I assume you are talking about the Server Explorer in Visual Studio. If you are talking about a SQL Server database that is being used by your application this can be done using the a constraints.

If you add two, one that checks that Weight > 129 and one that checks that Weight < 131, it should prevent people from entering values outside of those ranges.

That said I would probably enforce this business rule through your C# Application logic rather than in the Database structure.

In other words present people with a drop down list to select from that contains only the range of values that you want. You could do server side validation on the selected values if security is a concern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜