这仅用于调试目的.我们有一个滥用的存储过程,需要永远返回结果集. 目前优化过程是不可能的.我是否有可能将加载的数据集结果存储在某些地方,所以我不必一遍又一遍地调用存储过程.我可以继续测试我的.net代码.我不想将其缓存在内存中,而是将其存储在本地文件中.
DataSet ds = db.ExecuteDataSet(cmdobject);
//Store this result some where
//so next time I dont have to call the above method. Just pick up the stored result //from some where and continue with my testing.
Run Code Online (Sandbox Code Playgroud)
任何代码示例都会有帮助.
Well DataSet实现了ISerializable接口,因此您可以将其序列化为文件.
例:
DataSet ds = new DataSet();
if (File.Exists("SavedDataSet.dat"))
{
// If the serialized object exists, read it from the file
// and deserialize it
DataSet ds;
Stream stream = File.Open("SavedDataSet.dat", FileMode.Open);
BinaryFormatter bFormatter = new BinaryFormatter();
ds = (DataSet)bFormatter.Deserialize(stream);
stream.Close();
}
else
{
// If the serialized object doesn't exist, run the stored
// procedure and then serialize the result
ds = db.ExecuteDataSet(cmdobject);
Stream stream = File.Open("SavedDataSet.dat", FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, ds);
stream.Close();
}
Run Code Online (Sandbox Code Playgroud)