Click here to Skip to main content
15,896,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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")
Posted

1 solution

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.
 
Share this answer
 
Comments
Roman Mihai 23-May-12 15:58pm    
I have tried on the Validating event, but I need an example to retrieve the values for minimum salary and maximum salary from the table to use them for validation
Wendelius 23-May-12 16:08pm    
One easy way is to use SqlDataAdapter. For an example, see http://www.dotnetperls.com/sqldataadapter[^]
Roman Mihai 23-May-12 17:54pm    
I want to code something like this in my validating event:

int minimum = "SELECT MinimumSalary FROM Jobs WHERE JobId="+combobox_jobid.selectedValue;
int maximum = "SELECT MaximumSalary FROM Jobs WHERE JobId=" + combobox_jobid.selectedValue;

and the value entered in textbox_salary should be between minimum and maximum described above.

Sorry about all my questions, I understand your solutions, but in my mind I want to clear out if the implementation thought by me is possible or not.

Thanks a lot for all the help so far.
Wendelius 23-May-12 23:52pm    
Yes, you can do that using code like in the example. However, I wouldn't do it like this because everey time you validate the text box, yu query the database. This would make the program more resource consuming.

Instead if the amuont of jobs is fairly small, fetch them all into a datatable and then use that when you're validating the input.
Roman Mihai 24-May-12 4:01am    
I'm not looking to avoid resource consuming, as this project isn't one that will be sold. It's my college degree project and I just need to implement the things I have learnt in college for a chosen domain. The database will be quite small (I have 27 distinct jobs) and I don't think the number of employees will be more than 50-100.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900