Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a strange problem,
I'm working with win-form which is coding in c#..and sql server
In a form I have a Combo-box which is collected data by the database(say 1).
and later I have to Insert that particular value/member details into another database(say 2)
Here My problem raises,,Once My combo-box any value is inserted into 2nd database,that particular value/member should not visible in the combo-box for the next time on the same day..
Of course Here I'm using datetimepicker..
Here I'm using following code...and Of-course it is wrong..Please Help me

C#
SqlCommand cmd1 = new SqlCommand("select employee_id,Empployee_Name,date from dailyattendance", cn);
       SqlDataReader sdr;
       DataTable dt = new DataTable();
       sdr = cmd1.ExecuteReader();


       if (sdr.Read())
       {
           string employeeid = (string)sdr["employee_id"];
           string employeename = (string)sdr["Empployee_Name"];
           string date = (string)sdr["date"];


           try
           {
               //cn.Open();
               SqlCommand cmd = new SqlCommand("select employee_id,employee_name from Employee_Details", cn);
               SqlDataReader sdr1;
               DataTable dt1=new DataTable();

               sdr1 = cmd.ExecuteReader();
               dt1.Load(sdr1);
               if (sdr1.Read())
               {

                   string date1=dateTimePicker1.Value.ToString("dd/MM/yyyy");

                   if ()//here the main problem
                   {
                       string employeeid1 = (string)sdr1["employee_id"];
                       string employeename1 = (string)sdr1["employee_name"];
                       comboBox1.DisplayMember = employeeid1;
                       comboBox1.DisplayMember = employeename1;
                       comboBox1.DataSource=dt1;
                       cn.Close();
                   }
               }
c#
Posted
Comments
ZurdoDev 22-Sep-14 7:57am    
So, where are you stuck?
n shiva Ram 23-Sep-14 0:53am    
I don't know How to write code for my problem
As explained in my question I want to hide a combobox value when that particular value is already is in the Inserting table @RyanDev
jaket-cp 23-Sep-14 7:55am    
My suggestion would be to write the sql for the combobox to not include the member you do not want.
Looking at the SQL you could do something like:
select employee_id,employee_name from Employee_Details where employee_id not in (select employee_id from dailyattendance where date = 'TheDateYouWantToCheckFor');
n shiva Ram 24-Sep-14 1:19am    
Yes u are awesome,thanks @10454138

1 solution

C#
ConnectionStringSettings consettings = ConfigurationManager.ConnectionStrings["attendancemanagement"];
           string connectionString = consettings.ConnectionString;
           SqlConnection cn = new SqlConnection(connectionString);
           cn.Open();
           
           try
           {
               string dtp = dateTimePicker1.Value.ToString("dd/MM/yyyy");
               string query = "select employee_id,employee_name,image_of_employee,image_path from Employee_Details where employee_id not in (select employee_id from dailyattendance where date = '" + dtp + "')";
               
               SqlCommand cmd = new SqlCommand(query, cn);
               SqlDataReader dtr;
               dtr = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                dt.Load(dtr);
                
               foreach (DataRow row in dt.Rows)
               {
                   var name = (string)row["employee_name"];
                   row["employee_name"] = name.Trim();
               }

                comboBox1.ValueMember = "employee_id";
                comboBox1.DisplayMember = "employee_name";
                listBox1.ValueMember = "employee_id";
                listBox1.DisplayMember = "employee_name";            
                comboBox1.DataSource = dt;
                listBox1.DataSource = dt;

                comboBox1.SelectedItem = null;
                listBox1.SelectedItem = null;

               cn.Close();

           }

           catch (System.Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
 
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