C#.net Windows应用程序在插入数据库之前输入数据 [英] C#.net Windows Application Input data check before insert to Database

查看:63
本文介绍了C#.net Windows应用程序在插入数据库之前输入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#.net Windows应用程序在插入数据库之前输入数据检查

解决方案

您必须自己编写数据验证。


< blockquote>应验证用户输入数据。问题是你编写验证逻辑的地方。你的applilcation是Windows应用程序。因此,您应该在表示层中编写一些验证。例如



示例-1。提交订单的日期不应该大于当前数据或用户名不应为空。

您应该在Windows窗体中写入这种类型的验证,并在用户按提交/保存/时调用它编辑等按钮。您还可以将该逻辑写入业务模型/实体,实体应包含IsValid类型方法。此方法将返回validationResult类型对象,如果实体包含,则该对象可能包含任何无效数据。



示例-2>用户想从她的账户中提取资金。在该类型的验证中,您需要查询数据库以验证您的输入。在这种类型的验证逻辑中,您应该编写业务逻辑/域服务层。



如果您在应用程序中编写数据验证逻辑,则应该记住一个重点首先应该首先向数据库添加数据约束。它将确保您的数据/参照完整性。例如,主键/唯一索引,非空等等。


C#.net Windows Application Input data check before insert to Database

解决方案

You have to write validations for data yourself.


User input data should be validated. Question is where you write that validation logic. Your applilcation is windows application. So some validation you should write in your presentation layer. For example

Example-1. The date of submit order should not be greater then current data or User name should not be empty.
That type of validation you should write in your windows windows form and call it when user press submit/save/edit etc button. You can also write that logic to your business model/entity and entity should contain a IsValid type method. This method will return validationResult type object which may contain any invalid data if entity contain.

Example-2> User wants to withdraw money from her account. In that type of validation you need to query your database for verify your input. In that type of validation logic you should write your business logic/domain service layer.

One important point you should remember that if you write data validation logic in your application but you first should add data constraint to your database first. It will ensure your data/referential integrity. For example Primary key/Unique index, Not Null etc.


这篇关于C#.net Windows应用程序在插入数据库之前输入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆