小编Ami*_*eza的帖子

将xmlns属性添加到根元素

我有C#程序生成RDL文件用于报告服务中的whitch Show报告.我使用Linq到Xml来生成Xml.

当我尝试将xmlns XAttribute 添加到Report Element时,我遇到了几个问题.

我测试以下方法:

第一:

        XDocument d = new XDocument(
           new XDeclaration("1.0", "utf-8", "yes"),
           new XElement("Report",
               new XAttribute(XNamespace.Xmlns + "rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"),
               new XAttribute(XNamespace.Xmlns + "cl", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition"),
               new XAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"),
                   new XElement("DataSources", ""),
                   new XElement("DataSets", ""),
                   new XElement("ReportSections",
Run Code Online (Sandbox Code Playgroud)

这是我的代码中的一部分,显示如何生成xml:

第二:

XNamespace reportDef = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
        XDocument d = new XDocument(
           new XDeclaration("1.0", "utf-8", "yes"),
           new XElement(reportDef + "Report",
               new XAttribute(XNamespace.Xmlns + "rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"),
               new XAttribute(XNamespace.Xmlns + "cl", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition"),
                   new XElement("DataSources", ""),
                   new XElement("DataSets", ""),
                   new XElement("ReportSections",...
Run Code Online (Sandbox Code Playgroud)

第一种方法返回Error,第二种方法将属性xmlns …

c# xml linq linq-to-xml xml-namespaces

5
推荐指数
1
解决办法
2万
查看次数

在C#中禁用异常

我有c#程序,这从输入获取Sql查询并执行此操作.有时,This Query包含执行查询后的任何单词,返回"Divide By Zero Exception".

我想执行查询之前禁用SqlException 并检查其他输入的单词然后启用它.

c# exception

-3
推荐指数
1
解决办法
1630
查看次数

标签 统计

c# ×2

exception ×1

linq ×1

linq-to-xml ×1

xml ×1

xml-namespaces ×1