SQLXML使用了schema 和xsl 之后如何更新数据阿? 高手快来

晓峰-Bitcoin 2003-12-20 09:01:34
我使用SQLXML打开SQL SERVER取出数据,生成一个XML文件(SVG,是为了使用数据库中的数据动态生成图形),但是怎么杨来更新数据阿 ,我觉得应该是可以的,但是我用了以下的代码 有错误,清高手指点,
我的代码如下 ,
全局变量:
private System.Windows.Forms.DataGrid grid;
private SqlXmlCommand cmd=null;
private SqlXmlAdapter ad=null;
private DataSet ds=null;

点击button1 填充数据
String cnString ;
cnString="PROVIDER=SQLOLEDB;SERVER=(local);DATABASE=Northwind;INTEGRATED SECURITY=sspi;";

cmd=new SqlXmlCommand(cnString);
cmd.RootTag ="Test";
cmd.CommandType = SqlXmlCommandType.XPath ;
cmd.SchemaPath="C:\\Inetpub\\wwwroot\\Test\\Schema.xsd";
cmd.CommandText ="/Map[@mapID=2]";
cmd.XslPath = "C:\\Inetpub\\wwwroot\\Test\\xsl.xslt";


ad=new SqlXmlAdapter(cmd);
ds=new DataSet();
try
{

ad.Fill(ds);
grid.DataSource=ds;
}
catch(SqlXmlException E)
{
MessageBox.Show(E.ToString());
}
点击button2更新数据
try
{
ad.Update(ds);
}
catch(SqlXmlException E)
{
MessageBox.Show(E.ToString());
}
schema 文件 schema.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="MAP_LAYER" parent="METADATA_MAP" parent-key="mapID" child="METADATA_LAYER"
child-key="mapID" />
dasd
<sql:relationship name="LAYER_FEATURE" parent="METADATA_LAYER" parent-key="lyrID" child="DATA_FEATURE"
child-key="lyrID" /></xsd:appinfo>
</xsd:annotation>
<xsd:element name="Map" sql:relation="METADATA_MAP">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Layer" sql:relation="METADATA_LAYER" sql:relationship="MAP_LAYER" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Feature" sql:relation="DATA_FEATURE" sql:relationship="LAYER_FEATURE" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="FeatureID" type="xsd:integer" />
<xsd:attribute name="FeatureType" type="xsd:integer" />
<xsd:attribute name="Geometry" type="xsd:string" />
<xsd:attribute name="Points" type="xsd:string" />
<xsd:attribute name="X" type="xsd:integer" />
<xsd:attribute name="Y" type="xsd:integer" />
<xsd:attribute name="Text" type="xsd:string" />
<xsd:attribute name="imageURL" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="lyrID" type="xsd:integer" />
<xsd:attribute name="lyrName" type="xsd:string" />
<xsd:attribute name="lyrType" type="xsd:integer" />
<xsd:attribute name="tableName" type="xsd:string" />
<xsd:attribute name="fillColor" type="xsd:string" />
<xsd:attribute name="strokeColor" type="xsd:string" />
<xsd:attribute name="strokeWidth" type="xsd:integer" />
<xsd:attribute name="minScale" type="xsd:integer" />
<xsd:attribute name="maxScale" type="xsd:integer" />
<xsd:attribute name="legendID" type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="mapID" type="xsd:integer" />
<xsd:attribute name="mapName" type="xsd:string" />
<xsd:attribute name="mapDescription" type="xsd:string" />
<xsd:attribute name="Width" type="xsd:integer" />
<xsd:attribute name="Height" type="xsd:integer" />
<xsd:attribute name="Scale" type="xsd:integer" />
</xsd:complexType>
</xsd:element>
</xsd:schema>

xsl文件:xsl.xslt
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<xsl:output method="xml" indent="no" media-type="image/svg+xml"/>



<xsl:template match="Project">
<xsl:apply-templates select="Map"/>
</xsl:template>

<xsl:template match="Map">
<svg id="body" viewBox="0 0 800 600" xmlns:mysvg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">

<xsl:attribute name="width">
<xsl:value-of select="@Width" />
</xsl:attribute>

<xsl:attribute name="height">
<xsl:value-of select="@Height" />
</xsl:attribute>

<xsl:attribute name="id">
<xsl:value-of select="@mapName" />
</xsl:attribute>

<xsl:apply-templates select="Layer"/>
</svg>

</xsl:template>

<xsl:template match="Layer">
<g>
<xsl:attribute name="id">
<xsl:value-of select="normalize-space(@lyrName)" />
</xsl:attribute>
<xsl:attribute name="class">
<xsl:value-of select="@lyrName" />
</xsl:attribute>
<xsl:apply-templates select="Feature"/>
</g>
</xsl:template>

<xsl:template match="Feature">


<xsl:if test="@FeatureType[.='1']">
<circle r="1" style="fill:black" >
<xsl:attribute name="id">
<xsl:value-of select="@FeatureID" />
</xsl:attribute>
<xsl:attribute name="cx">
<xsl:value-of select="@X"/>
</xsl:attribute>
<xsl:attribute name="cy">
<xsl:value-of select="@Y"/>
</xsl:attribute>
</circle>
</xsl:if>
<xsl:if test="@FeatureType[.='2']">
<polyline style="fill:red">
<xsl:attribute name="id">
<xsl:value-of select="@FeatureID" />
</xsl:attribute>

<xsl:attribute name="points">
<xsl:value-of select="@Points" />
</xsl:attribute>
</polyline>
</xsl:if>

<xsl:if test="@FeatureType[.='3']">
<polygon style="fill:blue">
<xsl:attribute name="id">
<xsl:value-of select="@FeatureID" />
</xsl:attribute>

<xsl:attribute name="points">
<xsl:value-of select="@Points" />
</xsl:attribute>

</polygon>
</xsl:if>


<xsl:if test="@FeatureType[.='5']">
<text style="fill:blue">
<xsl:attribute name="id">
<xsl:value-of select="@FeatureID" />
</xsl:attribute>

<xsl:attribute name="id">
<xsl:value-of select="@FeatureID" />
</xsl:attribute>
<xsl:attribute name="x">
<xsl:value-of select="@X"/>
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="@Y"/>
</xsl:attribute>
<xsl:value-of select="@Text"/>

</text>
</xsl:if>
</xsl:template>





</xsl:stylesheet>

数据库中有几个表 ,可以从schema文件中看到,填充数据没有问题,使用层次结构显示该XML文件, 更新的时候显示的错误是
Microsoft.Data.SqlXml.SqlXmlException: SQLXML: error loading XML result (XML document must have a top level element.
) ---> System.Runtime.InteropServices.COMException (0x80004005): SQLXML: error loading XML result (XML document must have a top level element.
)
at Microsoft.Data.SqlXml.Common.ISQLXMLCommandManagedInterface.ExecuteToOutputStream()
at Microsoft.Data.SqlXml.SqlXmlCommand.innerExecute(Stream strm)
--- 内部异常堆栈跟踪的结尾 ---
at Microsoft.Data.SqlXml.SqlXmlCommand.ExecuteStream()
at Microsoft.Data.SqlXml.SqlXmlCommand.ExecuteNonQuery()
at Microsoft.Data.SqlXml.SqlXmlAdapter.Update(DataSet ds)
at WA6.Form1.button2_Click(Object sender, EventArgs e) in c:\documents and settings\asalei\my documents\visual studio projects\wa6\form1.cs:line 334



另外如果有对在ASP.NET在中使用SVG有兴趣的可以跟我联系 ,直接发展内短信把



...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓峰-Bitcoin 2003-12-24
  • 打赏
  • 举报
回复
ding
晓峰-Bitcoin 2003-12-22
  • 打赏
  • 举报
回复
多谢楼上 但是好像不是代码的问题 我只是想要问问这样能够更新数据库马?
elite2018 2003-12-22
  • 打赏
  • 举报
回复
你 试试 debug , 要不 给我 发代码 , 我 帮你 调试 一下 zhaoxun@onest.net
孟子E章 2003-12-20
  • 打赏
  • 举报
回复
你可以用隐藏的幀进行定时刷新
内容概要:本文围绕基于三重移相控制(TPS)的双有源桥(DAB)高频隔离DC-DC变换器开展系统性研究,重点构建了其在Simulink环境下的高精度仿真模型。研究全面涵盖SPS单相移相、DPS双重重移相与TPS三重移相等多种控制策略的建模、实现与性能对比,深入分析不同模式下变换器的功率传输特性、软开关实现条件及功率回流问题,旨在提升DAB在交直流混合微电网、能量路由器、多端口柔性互联装置等场景中的转换效率与动态响应能力。通过对ZVS(零电压切换)条件的精确控制与移相角参数的优化,有效降低了开关损耗,增强了系统整体能效与运行稳定性。该仿真模型具有良好的可扩展性,适用于复杂电能转换系统的科研验证与工程开发。; 适合人群:电力电子、电气工程及其自动化等相关专业的硕士研究生、博士生、科研人员以及从事新能源变换器、柔性输配电系统设计的工程技术人员。; 使用场景及目标:①掌握双有源桥DAB变换器的基本工作原理及其在高频隔离场合的核心优势;②深入理解三重移相控制策略的设计机理、控制自由度分配及其在效率优化中的关键作用;③构建并调试可用于科研论文撰写、项目申报或实际系统验证的高保真Simulink仿真模型,支撑理论分析与实验对比。; 阅读建议:建议结合MATLAB/Simulink平台进行动手实践,重点关注主电路拓扑搭建、移相控制模块设计、驱动信号时序配置及ZVS实现条件的仿真观测,推荐通过对比SPS、DPS与TPS三种模式的稳态与动态响应曲线,深入掌握各控制策略的适用边界与优化方向。
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧