SQL数据库查询到XML文档 [英] SQL Database Query to XML Document

查看:89
本文介绍了SQL数据库查询到XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在关注nikhulion的帖子,并由bijeesh回答.我是C#的新手,想知道如何通过bijeesh实际编译和运行类解析.

此处包含的代码带有汇编错误;请提供紧急协助:-)

Hi
I have been following a post by nikhulion and answered by bijeesh. I am a novice at C# and would like to know how to actually compile and run the class resolution by bijeesh.

Code included here with error on assembly; Urgent assistance required please :-)

private void WriteXmlMethod()
{
    string constring = ConfigurationManager.ConnectionStrings ["YourConnectionString"].ToString();
    SqlConnection con = new SqlConnection(constring);
    con.Open();
    string query = "select * from tbl_newsBee";
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataReader dr = cmd.ExecuteReader();
    XDocument doc = new XDocument();
    XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
    doc.Add(declaration);
    XElement element1 = new XElement("Newses");
    XElement element2 = null;
    while (dr.Read())
    {
        element2 = new XElement("News", new XAttribute("link", dr[2].ToString()), new XAttribute("des", dr[1].ToString()));
        element2.Add(dr[3].ToString());
        element1.Add(element2);
    }
    con.Close();
    string filename = Server.MapPath("E:/myXmlDoc.xml");
    doc.Save(filename);
}


发生的错误:
类型"System.ComponentModel.Component"在未引用的程序集中定义.
您必须添加对程序集的引用:
``系统,版本= 4.0.0.0,文化=中性,PublicKeyToken = b77a5c561934e089''在:
C:\ Users \ Administrator \ Documents \ Visual Studio 2010 \ Projects \ WtiteXml.cs
行:13
栏:9
其他信息:TestXML

由EdMan196总体上增加了预标记/格式,并使错误消息更具可读性.


Error that occurred:
The type ''System.ComponentModel.Component'' is defined in an assembly that is not referenced.
You must add a reference to assembly:
''System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'' in:
C:\Users\Administrator\Documents\Visual Studio 2010\Projects\WtiteXml.cs
Line: 13
Column: 9
Other Info: TestXML

Edit by EdMan196: Added pre tags/formatting in general and made error message a bit more readable.

推荐答案

错误提示您缺少参考,所以无论您是什么用于编译代码(Visual Studio解决方案/项目?).无论使用什么工具,都需要添加对该库的引用-这意味着您要告诉编译器类需要使用的系统代码库在哪里.在Visual Studio中,这非常简单:

1.右键单击您的项目
2.单击添加引用"
3.转到.Net选项卡
4.找到名为(特别是)"System.ComponentModel.Component"的项,或者如果该项不存在,则只需添加"System.ComponentModel"一项(应存在).您可能必须添加后一个引用,因为System.ComponentModel.Component可能包含在System.ComponentModel编译的代码库(文件名为dll)中.

希望这会有所帮助,
Ed
Well the error says you have a reference missing so whatever you are using to compile the code (Visual Studio Solution/Project?). Whatever you are using you will need to add a reference to the library - what this means is you are telling the compiler where the system code library that your class needs to be compiled with, is. In Visual Studio it''s very easy:

1. Right click on your project
2. Click "add Reference"
3. Go to the .Net tab
4. Find the item named (specifically) "System.ComponentModel.Component" or if that doesn''t exist just add the "System.ComponentModel" one (which should exist). You may have to add the latter reference because System.ComponentModel.Component may be contained within the System.ComponentModel compiled code library (dll for file name).

Hope this helps,
Ed


这篇关于SQL数据库查询到XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆