Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two combobox as follows;

Name combobox
Days combobox

in the name retrieved from the database and display into the combobox.
in the days column manually typed in the code sunday to saturday.

in the run mode i select the name and select the days and click the save button. the records are saved in the database. it is working fine.

for example as follows;

Name Suresh
Days Sunday

the above record is saved in the database.

then i have one search button,when i click the search button from the database records are displayed in the datagridview,when i click the datagridview, the particular record is displayed in the respective combobox.

suppose when i select the suresh and select the sunday and click save button,

that time validate ,For suresh sunday is already exists.

for that how to validate the Combobox.using csharp.

how can i do using csharp it is windows application.

Thanks & Rgds,
Narasiman P.

1 solution

From save button you should read user current selection. How you get selected value from combobox depends on how you bind/add data to combobox data. One way like
var name = comboBox1.SelectedItem.ToString();
var day = comboBox2.SelectedItem.ToString();

After getting user selection from combobox you just query to database using library api. Query like
SELECT Count(*) FROM YourTable WHERE EmployeeName = @name AND DayName = @day;

need to execute in database and receive the count result If this count > 0 then the employee and dayname exists. Then you need to show validation message otherwise save the selection.
Share this answer

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