Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table in the following format
SQL
Id   Employee_Id    Cat_Id
1      SSS            1
2      DDD            2
3      FFF            1 
4      GGG            2

I WANT to change employee Category base on date.using following code
C#
DateTime date = SafeConvert.ToDateTime(txtDate.Text);
           Int16 day = Convert.ToInt16(SafeConvert.ToDateTime(txtDate.Text).Day);
           if (day % 2 == 0)
           {
               var empcatone = (from ec in entities.EmployeeCategories where ec.Category_Id == 1 select ec).ToList();
                foreach (var Empcatone in empcatone)
                {

                     Empcatone.Category_Id = 2;



                }
                var empcattwo = _service.GetAllEmployeeCategory().Where(x => x.Category_Id == 2).ToList();
                foreach (var Empcattwo in empcattwo)
                {
                    Empcattwo.Category_Id = 1;

                }

           }
           else if (day % 2 != 0)
           {
               var empcatone = _service.GetAllEmployeeCategory().Where(x => x.Category_Id == 2).ToList();
               foreach (var Empcatone in empcatone)
               {
                   Empcatone.Category_Id = 1;

               }
               var empcattwo = _service.GetAllEmployeeCategory().Where(x => x.Category_Id == 1).ToList();
               foreach (var Empcattwo in empcattwo)
               {
                   Empcattwo.Category_Id = 2;

               }


           }

when i run there is no change in the table column
Posted
Comments
deepankarbhatnagar 6-Apr-15 5:43am    
please elaborate your query..
Sajid227 6-Apr-15 5:52am    
in my guery first i got day from date,then checked it for even or odd,then base on EVEN OR ODD ,i want to change the category_Id of employee in EmployeeCategory table From 1 to 2 and from 2 to one.
deepankarbhatnagar 6-Apr-15 5:55am    
OK
Jim_Varney 7-Apr-15 1:57am    
You're not calling the .SaveChanges() method?

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