Click here to Skip to main content
16,004,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I got the following runtime error:
Type 'Employee_Schedule.EmployeesDBEntities' in Assembly 'Employee Schedule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

while i'm binding listview to a datatable using this code
C#
public DataTable GetDataSource()
        {
            DataTable dt = new DataTable();
            dt = new DataTable();
            dt.Columns.Add("Id");
            dt.Columns.Add("Day");
            dt.Columns.Add("WorkingDay");
            dt.Columns.Add("Vacation");
            dt.Columns.Add("Holyday");

            var employeeStatus = ctx.EmployeeStatus.Where(a => a.Month == selectedMonth);

            int daysCount = DateTime.DaysInMonth(DateTime.Now.Year, selectedMonth);

            for (int i = 1; i <= daysCount; i++)
            {
                DataRow dr = dt.NewRow();
              dr["Day"] = i.ToString();
                foreach (var item in employeeStatus)
                {
                    if (item.Day == i)
                    {
                        dr["Id"] = item.Id;
                        if (item.DayType == 0)
                        {
                            dr["WorkingDay"] = "1";
                            dr["Vacation"] = "0";
                            dr["Holyday"] = "0";
                        }
                        else if (item.DayType == 1)
                        {
                            dr["WorkingDay"] = "0";
                            dr["Vacation"] = "1";
                            dr["Holyday"] = "0";
                        }
                        else
                        {
                            dr["WorkingDay"] = "0";
                            dr["Vacation"] = "0";
                            dr["Holyday"] = "1";
                        }

                        break;
                    }

                }
                if (string.IsNullOrEmpty(dr["WorkingDay"].ToString()) &&
                            string.IsNullOrEmpty(dr["Vacation"].ToString()) &&
                            string.IsNullOrEmpty(dr["Holyday"].ToString()))
                {
                    dr["Id"] = "0";
                    dr["WorkingDay"] = "0";
                    dr["Vacation"] = "0";
                    dr["Holyday"] = "0";
                }

                dt.Rows.Add(dr);
            }

            return dt;
        }

Any suggestions ??
Posted
Updated 22-Apr-11 7:51am
v2
Comments
OriginalGriff 22-Apr-11 14:13pm    
Any particular line?
Bruno Tagliapietra 22-Apr-11 16:30pm    
I guess the error isn't firing in this method you posted here: you're reading, there's no serialization involved

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