SQLXML使用了schema 和xsl 之后如何更新数据阿? 高手快来
我使用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有兴趣的可以跟我联系 ,直接发展内短信把