怎样把xml存入数据库,请前辈给个例子,小弟先感谢了! 本帖最后由 salecn 于 2010-07-01 22:50:24 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 XmlDocument doc=new XmlDocument();dic.LoadXML("");DataSet ds=new DataSet();ds.ReadXml("");XmlDocument遍历 string path = strXmlPath; DataSet ds = new DataSet(); XmlDocument doc = new XmlDocument(); try { //将XML文件读入内存 doc.Load(strXmlPath); XmlNodeReader reader = new XmlNodeReader(doc); //将XML文件写入到DataSet ds.ReadXml(reader); reader.Close(); } catch (Exception ex) { return; } //ds中有两张表,一张存有type //另一张result_id,msid,area_no,area_name //楼主再将ds写入数据库即可 希望能帮到你,呵呵 table 本来就是从xml 过来的然后你自己构造一个table 就ok 了 protected void insertdata_Click(object sender, EventArgs e) { try { string constr = "Server=.;Database=Test;Uid=sa;Pwd=123456"; SqlConnection con = new SqlConnection(constr); con.Open(); insertTableData(con); con.Close(); } catch (Exception ex) { } finally { } } private void insertTableData(SqlConnection con) { XmlDocument xmld = new XmlDocument(); xmld.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\strXml.xml"); XmlNode xmlnode = xmld.SelectSingleNode("yhjx_result"); XmlNode typenode = xmlnode.SelectSingleNode("response"); string type = typenode.ChildNodes[1].InnerText; XmlNode resultnode = typenode.SelectSingleNode("result"); string result_id = resultnode.ChildNodes[1].InnerText; string msid = resultnode.ChildNodes[3].InnerText; string area_no = resultnode.ChildNodes[5].InnerText; string area_name = resultnode.ChildNodes[7].InnerText; string insertstr = "insert into resulttable values('" + type + "','" + result_id + "','" + msid + "','" + area_no + "','" + area_name + "')"; SqlCommand sqlcom = new SqlCommand(insertstr,con); sqlcom.ExecuteNonQuery(); } insert into table1 (memo) values("xml") ++++++++++大家来看看 不知到什么毛病++++++++++ 面试题 抓取网页代码原理 3dmax中的数据转换格式 去一美资外包公司,不会做,干脆把题拿回来了 foreach 循环的时间是for 循环的30% 特此散分 用EventLog写入事件日志后,在windows的日志查看器中为何看不到,但是用程序能读出写入的日志! [急急急]为什么我用BinaryWriter往文件里写字符串,会在写入文件的字符串前多出一个字节来? 我把那个预编译头选成“不使用预编译头”还是有错误啊 提示 请问如何调用外部程序 屏幕截图的方法!! winform中DataGridView中显示图片的问题!
dic.LoadXML("");
DataSet ds=new DataSet();
ds.ReadXml("");
XmlDocument遍历
DataSet ds = new DataSet();
XmlDocument doc = new XmlDocument();
try
{
//将XML文件读入内存
doc.Load(strXmlPath);
XmlNodeReader reader = new XmlNodeReader(doc);
//将XML文件写入到DataSet
ds.ReadXml(reader);
reader.Close();
}
catch (Exception ex)
{
return;
} //ds中有两张表,一张存有type
//另一张result_id,msid,area_no,area_name
//楼主再将ds写入数据库即可
希望能帮到你,呵呵
{
try
{
string constr = "Server=.;Database=Test;Uid=sa;Pwd=123456";
SqlConnection con = new SqlConnection(constr);
con.Open();
insertTableData(con);
con.Close();
}
catch (Exception ex) { }
finally
{
}
} private void insertTableData(SqlConnection con)
{
XmlDocument xmld = new XmlDocument();
xmld.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\strXml.xml");
XmlNode xmlnode = xmld.SelectSingleNode("yhjx_result");
XmlNode typenode = xmlnode.SelectSingleNode("response");
string type = typenode.ChildNodes[1].InnerText;
XmlNode resultnode = typenode.SelectSingleNode("result");
string result_id = resultnode.ChildNodes[1].InnerText;
string msid = resultnode.ChildNodes[3].InnerText;
string area_no = resultnode.ChildNodes[5].InnerText;
string area_name = resultnode.ChildNodes[7].InnerText; string insertstr = "insert into resulttable values('" + type + "','" + result_id + "','" + msid + "','" + area_no + "','" + area_name + "')";
SqlCommand sqlcom = new SqlCommand(insertstr,con);
sqlcom.ExecuteNonQuery();
}