-2
存在一個數據庫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();
}
}
}