如何将XML文件写入数据库
将xml文件转成string
public string XMLDocumentToString(XmlDocument doc) { MemoryStream stream = new MemoryStream(); XmlTextWriter writer = new XmlTextWriter(stream, null); writer.Formatting = Formatting.Indented; doc.Save(writer); //转换 StreamReader sr = new StreamReader(stream, System.Text.Encoding.UTF8); stream.Position = 0; string xmlString = sr.ReadToEnd(); sr.Close(); stream.Close(); return xmlString; }
将string转成DataTable
private DataSet GetXmlImages(string subFolder)
{
string[] xmlFiles = Directory.GetFiles(SourceDirectory + "\\" + subFolder, "*.xml", SearchOption.AllDirectories);
if (xmlFiles.Length > 0)
{
string xmlFilePath = xmlFiles[0];
XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath);
string xmlfile = XMLDocumentToString(doc);
DataSet xmlInfo = new DataSet(); ;
xmlInfo = ConvertXMLToDataSet(xmlfile);
return xmlInfo;
}
return null;
}
将DataTable写入数据库
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。