自己写了重载DataTable的类,并实现了ISerializable接口
protected BaseDataTable(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context):base()
{
System.Collections.ArrayList colNames = new System.Collections.ArrayList();
System.Collections.ArrayList colTypes = new System.Collections.ArrayList();
System.Collections.ArrayList dataRows = new System.Collections.ArrayList();
colNames = (System.Collections.ArrayList) info.GetValue("ColNames", typeof(System.Collections.ArrayList));
colTypes = (System.Collections.ArrayList) info.GetValue("ColTypes", typeof(System.Collections.ArrayList));
dataRows = (System.Collections.ArrayList) info.GetValue("DataRows", typeof(System.Collections.ArrayList));
for(int i=0; i<colNames.Count; i++)
{
System.Data.DataColumn col = new System.Data.DataColumn(colNames[i].ToString(),
Type.GetType(colTypes[i].ToString() ));
this.Columns.Add(col);
}
for(int i=0; i<dataRows.Count; i++)
{
System.Data.DataRow row = this.NewRow();
row.ItemArray = (object[]) dataRows[i];
this.Rows.Add(row);
}
}
这样写的一个问题是没有办法保存DataRow的DataRowState,不知道有没有办法实现ISerializable接口,并保存每一行的DataRowState
protected BaseDataTable(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context):base()
{
System.Collections.ArrayList colNames = new System.Collections.ArrayList();
System.Collections.ArrayList colTypes = new System.Collections.ArrayList();
System.Collections.ArrayList dataRows = new System.Collections.ArrayList();
colNames = (System.Collections.ArrayList) info.GetValue("ColNames", typeof(System.Collections.ArrayList));
colTypes = (System.Collections.ArrayList) info.GetValue("ColTypes", typeof(System.Collections.ArrayList));
dataRows = (System.Collections.ArrayList) info.GetValue("DataRows", typeof(System.Collections.ArrayList));
for(int i=0; i<colNames.Count; i++)
{
System.Data.DataColumn col = new System.Data.DataColumn(colNames[i].ToString(),
Type.GetType(colTypes[i].ToString() ));
this.Columns.Add(col);
}
for(int i=0; i<dataRows.Count; i++)
{
System.Data.DataRow row = this.NewRow();
row.ItemArray = (object[]) dataRows[i];
this.Rows.Add(row);
}
}
这样写的一个问题是没有办法保存DataRow的DataRowState,不知道有没有办法实现ISerializable接口,并保存每一行的DataRowState
解决方案 »
- C#中获取打印机当前状态 (打印机是否有纸) 100分求救。
- c#10个数排序题(新手提问)
- linq中的查询中的Lambda能动态生成吗????
- .net2.0中做mdi窗体,父子菜单如何合并?
- 满分求一个自定义控件几天都没搞定的问题,还请大家给看看
- 200分求 在DataGrid中为每一个输出行(tr)增加一个从数据库中读取的ID值
- 关于httpwebrequest的pos 新浪微博数据进行登录的问题
- Webrequest获取的图像保存后再使用出错
- 困惑多年的问题:关于实体关系映射
- 一个新闻系统的问题,关于HTTP查询字符串变量的取值问题!(我的分都快没了 只能40分求了!)
- c#用什么方法去判断二个类相同
- 我在网上下载了一个打印控件,但不知道怎么用?请教各位
不过你要加上实现 void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext context)
{ info.SetType(typeof(this)); }
方法
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, mydatatale);就可以了