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有兴趣的可以跟我联系 ,直接发展内短信把



...全文
98 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓峰-Bitcoin 2003-12-24
  • 打赏
  • 举报
回复
ding
晓峰-Bitcoin 2003-12-22
  • 打赏
  • 举报
回复
多谢楼上 但是好像不是代码的问题 我只是想要问问这样能够更新数据库马?
elite2018 2003-12-22
  • 打赏
  • 举报
回复
你 试试 debug , 要不 给我 发代码 , 我 帮你 调试 一下 zhaoxun@onest.net
孟子E章 2003-12-20
  • 打赏
  • 举报
回复
你可以用隐藏的幀进行定时刷新

62,243

社区成员

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

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

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

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