Flashmx2004中的DataGrid如何绑定asp.net的数据集:
<%@ Webservice Language="C#" class="test" %>
using System;
using System.Data;
using System.Web.Services;
using System.Data.OleDb;
public class test:WebService
{
[WebMethod]
public DataSet getds()
{
DataSet ds=new DataSet();
OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/service.mdb");
OleDbDataAdapter da=new OleDbDataAdapter("select top 3 id,name,content from example",conn);
conn.Open();
da.Fill(ds,"example");
conn.Close();
return ds;
}
}
调试的时候,调用getds方法,可以得到如下XML文件:
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://tempuri.org/">
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="example">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int" minOccurs="0" />
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="content" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<example diffgr:id="example1" msdata:rowOrder="0">
<id>1</id>
<name>lau</name>
<content>hello</content>
</example>
<example diffgr:id="example2" msdata:rowOrder="1">
<id>2</id>
<name>xiao</name>
<content>it's good</content>
</example>
<example diffgr:id="example3" msdata:rowOrder="2">
<id>3</id>
<name>bb</name>
<content>wa~</content>
</example>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
返回的这个DataSet是[object Object]类型,根据wsdl得到的results的数据类型是.net DataSet,不过在flash固有的数据类型里并不包括这项。
经过大量的测试终于找到了两种解决办法:
办法一:
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlDataAdapter da=new SqlDataAdapter("select * from BBS_灌水乐园_疯逛灌水_发贴",conn);
DataSet ds=new DataSet();
conn.Open();
da.Fill(ds);
XmlDataDocument xmlDoc=new XmlDataDocument(ds);
Return xmlDoc.InnerXml //这样返回的就是xml格式的dataset
在Flash中接受的办法:
my_xml=new XML();
my_xml.parse("这里是你通过webservice得到的那个结果(也就是我的代码里最后返回的xmlDoc.innerxml)");之后就把结果传到了flash里,my_xml就是xml格式的dataset,然后你在帮定到datagrid里.OK!试试吧.