Я получаю следующую ошибку при сериализации объекта в пары.
Type 'System.Data.DataRow' in Assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
DataTable mytable = new DataTable("mytable"); getMaxWorkID = Convert.ToInt32(objSQL.ExecuteSclar("select ISNULL(Max(workId),0) as workId from T_cuttingList")); con.Open(); SqlCommand cmd = new SqlCommand("sp_cuttingMeasurement", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mode", "selectHead"); cmd.Parameters.AddWithValue("@workId", getMaxWorkID); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dtHead = new DataTable(); da.Fill(dtHead); con.Close(); int sno = 0; DataRow dr = null; if (dtHead.Rows.Count > 0) { foreach (DataRow rows in dtHead.Rows) { // Head to add mytable **** START *** if (ViewState["Row"] != null) { mytable = (DataTable)ViewState["Row"]; if (mytable.Rows.Count > 0) { dr = mytable.NewRow(); sno = sno + 1; dr["SNo"] = sno; dr["Type"] = rows["Type"].ToString(); dr["Size"] = rows["Size"].ToString(); dr["Height"] = string.Empty; dr["Nos"] = string.Empty; dr["typeval"] = string.Empty; dr["Sqft"] = string.Empty; mytable.Rows.Add(dr); ViewState["Row"] = mytable; } } else { mytable.Columns.AddRange(new DataColumn[7] { new DataColumn("SNo", typeof(string)), new DataColumn("Type", typeof(string)), new DataColumn("Size", typeof(string)), new DataColumn("Height", typeof(string)), new DataColumn("Nos", typeof(string)), new DataColumn("typeval", typeof(string)), new DataColumn("Sqft",typeof(string)) }); dr = mytable.NewRow(); sno = sno + 1; dr["SNo"] = sno; dr["Type"] = rows["Type"].ToString(); dr["Size"] = rows["Size"].ToString(); dr["Height"] = string.Empty; dr["Nos"] = string.Empty; dr["typeval"] = string.Empty; dr["Sqft"] = string.Empty; mytable.Rows.Add(dr); ViewState["Row"] = mytable; } // Head to add mytable **** END *** // Child Parent to add mytable **** START *** int headId = 0; headId = Convert.ToInt32(rows["Id"].ToString()); ViewState["workId"] = rows["workId"].ToString(); con.Open(); SqlCommand cmd1 = new SqlCommand("sp_cuttingMeasurement", con); cmd1.CommandType = CommandType.StoredProcedure; cmd1.Parameters.AddWithValue("@mode", "getparent"); cmd1.Parameters.AddWithValue("@cId", headId); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dtparent = new DataTable(); da1.Fill(dtparent); con.Close(); if (dtparent.Rows.Count > 0) { foreach (DataRow drparent in dtparent.Rows) { if (ViewState["Row"] != null) { mytable = (DataTable)ViewState["Row"]; if (mytable.Rows.Count > 0) { dr = mytable.NewRow(); dr["SNo"] = string.Empty; dr["Type"] = string.Empty; dr["Size"] = drparent["width"].ToString(); dr["Height"] = drparent["height"].ToString(); dr["Nos"] = drparent["nos"].ToString(); dr["typeval"] = drparent["extra"].ToString(); dr["Sqft"] = drparent["sqft"].ToString(); mytable.Rows.Add(dr); ViewState["Row"] = mytable; } } } } // Child Parent to add mytable **** END *** // Draw / Shutter to add mytable **** START *** int typeId = 0; string AtMode = ""; typeId = Convert.ToInt32(rows["typeId"].ToString()); con2.Open(); SqlCommand cmd8 = new SqlCommand("sp_cuttingMeasurement", con2); cmd8.CommandType = CommandType.StoredProcedure; cmd8.Parameters.AddWithValue("@mode", "selDrawShutterFMD3"); cmd8.Parameters.AddWithValue("@typeId", typeId); cmd8.Parameters.AddWithValue("@Id", headId); SqlDataAdapter da8 = new SqlDataAdapter(cmd8); DataTable dtparent1 = new DataTable(); da8.Fill(dtparent1); con2.Close(); ViewState["parent1"] = null; if (dtparent1.Rows.Count > 0) { foreach (DataRow drparent1 in dtparent1.Rows) { if (ViewState["Row"] != null) { mytable = (DataTable)ViewState["Row"]; if (mytable.Rows.Count > 0) { if (ViewState["parent1"] != null) { dr = mytable.NewRow(); dr["SNo"] = string.Empty; dr["Type"] = string.Empty; dr["Size"] = drparent1["width"].ToString(); dr["Height"] = drparent1["height"].ToString(); dr["Nos"] = drparent1["nos"].ToString(); dr["typeval"] = drparent1["stype"].ToString(); dr["Sqft"] = drparent1["sqft"].ToString(); mytable.Rows.Add(dr); ViewState["Row"] = mytable; ViewState["parent1"] = drparent1; } else { dr = mytable.NewRow(); dr["SNo"] = string.Empty; dr["Type"] = "Draw/Shutter"; dr["Size"] = rows["hwidth"].ToString(); dr["Height"] = rows["hheight"].ToString(); dr["Nos"] = string.Empty; dr["typeval"] = string.Empty; dr["Sqft"] = string.Empty; mytable.Rows.Add(dr); dr = mytable.NewRow(); dr["SNo"] = string.Empty; dr["Type"] = string.Empty; dr["Size"] = drparent1["width"].ToString(); dr["Height"] = drparent1["height"].ToString(); dr["Nos"] = drparent1["nos"].ToString(); dr["typeval"] = drparent1["stype"].ToString(); dr["Sqft"] = drparent1["sqft"].ToString(); mytable.Rows.Add(dr); ViewState["Row"] = mytable; ViewState["parent1"] = drparent1; } } } } } // Draw / Shutter to add mytable **** END *** } }
Что я уже пробовал:
By reading the exception, it looks like there is a dataRow in the object which is not serialized. How can I identify the dataRow which is causing this problem in my code?