如何查看我创建的序列化数据

时间:2014-10-01 01:38:48

标签: c# asp.net serialization

存在一个包含以下内容的数据库MDFserializer.MDF

id    col1  col2  col3
----------------------    
1      11    22    33
2      44    55    66
3      77    88    99

写入或调试时没有错误。

如何查看我创建的序列化数据?

protected void Button1_Click(object sender, EventArgs e)
{
        String connStr = ConfigurationManager.ConnectionStrings["MDFserializerdb"].ConnectionString;
        String cmdStr = "SELECT * FROM [Table1];";
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        try
        {
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                using (SqlCommand cmd = new SqlCommand(cmdStr, conn))
                {
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                    Dictionary<string, object> row;

                    foreach (DataRow dr in dt.Rows)
                    {
                        row = new Dictionary<string, object>();

                        foreach (DataColumn col in dt.Columns)
                        {
                            row.Add(col.ColumnName, dr[col]);
                        }

                        rows.Add(row);
                    } 

                    serializer.Serialize(rows);
                    conn.Close();
                    cmd.Dispose();
                    conn.Dispose();
                }
            }
        }
        catch (Exception Exception)
        {
            Label1.Text = Exception.ToString();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

var dataYouCreated = serializer.Serialize(rows);