怎样将一个dataSet的表保存成文件?可以保存成什么类型文件?分别是怎样做的?

wwxc18 2004-01-25 10:43:55
怎样将一个dataSet的表保存成文件?可以保存成什么类型文件?分别是怎样做的?
...全文
80 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
izzard 2004-01-25
  • 打赏
  • 举报
回复
.NET 数据集是以 XML 形式表示的数据视图,是一种数据关系视图

DataSet 可将数据和架构作为 XML 文档进行读写。数据和架构可通过 HTTP 传输,并在支持 XML 的任何平台上被任何应用程序使用。可使用 WriteXmlSchema 方法将架构保存为 XML 架构,并且可以使用 WriteXml 方法保存架构和数据。若要读取既包含架构也包含数据的 XML 文档,使用 ReadXml 方法。


private void WriteXmlToFile(DataSet thisDataSet) {
if (thisDataSet == null) { return; }
// Create a file name to write to.
string filename = "myXmlDoc.xml";
// Create the FileStream to write with.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);
// Create an XmlTextWriter with the fileStream.
System.Xml.XmlTextWriter myXmlWriter =
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
// Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXmlWriter);
myXmlWriter.Close();
}

private void WriteSchemaWithXmlTextWriter(DataSet thisDataSet){
// Set the file path and name. Modify this for your purposes.
string filename="mySchema.xml";
// Create a FileStream object with the file path and name.
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename,System.IO.FileMode.Create);
// Create a new XmlTextWriter object with the FileStream.
System.Xml.XmlTextWriter MyXmlTextWriter =
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
// Write the schema into the DataSet and close the reader.
thisDataSet.WriteXmlSchema(MyXmlTextWriter );
MyXmlTextWriter.Close();
}
triout 2004-01-25
  • 打赏
  • 举报
回复
可以从DataSet对象获得对应的Shema和数据xml,你可以通过io操作把shema和xml保存到文件也可以通过DataSet对象的SaveShema和SaveXml方法保存。
acewang 2004-01-25
  • 打赏
  • 举报
回复
CSV

see: http://www.21tx.com/school/dotnet/csharp/000149374240026.htm

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧