通过SQL表中的值验证的C#文本框值 [英] C# textbox value validated by value from sql table

查看:59
本文介绍了通过SQL表中的值验证的C#文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试为项目创建应用程序,并且具有以下规范:

-我创建了一个看起来像数据输入表单的C#表单(如果所有数据均有效,则只要按一下按钮,它就会在数据库中插入值).
-我有一个具有以下结构的JOBS表:JobId,JobName,DepartmentId,MinimumSalary,MaximumSalary和EMPLOYEES表,其中(其中包括)雇员的薪水.
-在我的表单中,我创建了2个数据绑定组合框(一个用于部门,一个用于工作,最后一个被第一个过滤),并将所选部门和所选工作的ID传递给数据库.
在这里,我遇到了一个问题:当我从薪水中输入值时(在C#表单中,为薪水文本框),我想创建一个验证,该验证仅接受JOBS表中的值MINIMUM SALARY和MAXIMUM SALARY之间的值

Hi,

I''m trying to create an application for a project and I have the following specifications:

- I have created a C# form that looks like a data entry form (if all data are valid, on the press of a button it inserts values in database).
- I have the JOBS table with the following structure: JobId, JobName, DepartmentId, MinimumSalary, MaximumSalary and the EMPLOYEES table which contains (among others) the employee''s salary.
- in my form I have created 2 data-bound comboboxes (one for department, one for job, the last one filtered by the first one) and passes to the database the ids of the selected department and the selected job.

Here I have stumbled into my problem: when I enter the value from salary (in the C# form, the textbox for salary) I want to create a validation that accepts only values between the values MINIMUM SALARY and MAXIMUM SALARY from the JOBS table, values specific for the selected job (a comparation between the user inserted value in the C# form and the values from SELECT MINIMUMSALARY/MAXIUMSALARY FROM JOBS WHERE JOBID="value passed from the combobox in which I have selected the job")

推荐答案

如果这是表单,则可以使用例如 ^ ]事件,以检查文本框是否包含有效值.

因此,当程序启动,窗口打开等时,将所有必要的信息提取到例如数据表中,并在您的验证中使用.
If this is forms, you can use for example Validating[^] event to check if the text box contains valid values.

So when the program start, window opens etc, fetch all necessary information to for example a data table and use that in your validation.


这篇关于通过SQL表中的值验证的C#文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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