#region 序列化文件和反序列化
public void Serialize(string path, DataTable dt)
{
try
{
FileStream fs = new FileStream(path, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, dt);
fs.Close();
MessageBox.Show("文件保存成功");
}
catch (Exception)
{
MessageBox.Show("文件保存失败");
}
}
public DataTable Deserialize(string path)
{
DataTable dtt = new DataTable();
try
{
FileStream fs = new FileStream(path, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
dtt = (DataTable)bf.Deserialize(fs);
fs.Close();
}
catch (Exception)
{
MessageBox.Show("读取文件失败!");
}
return dtt;
}
#endregion
public void Serialize(string path, DataTable dt)
{
try
{
FileStream fs = new FileStream(path, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, dt);
fs.Close();
MessageBox.Show("文件保存成功");
}
catch (Exception)
{
MessageBox.Show("文件保存失败");
}
}
public DataTable Deserialize(string path)
{
DataTable dtt = new DataTable();
try
{
FileStream fs = new FileStream(path, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
dtt = (DataTable)bf.Deserialize(fs);
fs.Close();
}
catch (Exception)
{
MessageBox.Show("读取文件失败!");
}
return dtt;
}
#endregion