public static void create_xml(string sql, string top_node, string xml_filename) { String se = System.AppDomain.CurrentDomain.BaseDirectory; string consql = ConfigurationSettings.AppSettings["consql"].ToString(); SqlConnection con = new SqlConnection(consql); con.Open(); SqlCommand cmd = new SqlCommand(sql,con); System.Xml.XmlTextReader rd; rd = (System.Xml.XmlTextReader)cmd.ExecuteXmlReader(); System.IO.StreamWriter w = new System.IO.StreamWriter(xml_filename, false, System.Text.Encoding.GetEncoding("gb2312")); w.WriteLine("<?xml version='1.0'encoding='gb2312'?>"); w.WriteLine("<"+top_node+">"); while (rd.IsStartElement()) w.WriteLine(rd.ReadOuterXml()); w.WriteLine("</"+top_node+">"); w.Close(); rd.Close(); con.Close(); }
下面是调用方法的代码
protected void Button5_Click(object sender, EventArgs e) { string xml = TextBox5.Text; string gen = "stundet"; stat.create_xml("select stor_id,stor_name,stor_address from stores for xml auto",gen,Server.MapPath(""+xml+".xml")); }
运行后出现这样错误
无法将类型为“System.Xml.XmlTextReaderImpl”的对象强制转换为类型“System.Xml.XmlTextReader”。
请问应该如何改这个错误呢???
- 2 回答
- 0 关注
- 467 浏览
添加回答
举报
0/150
提交
取消