从.net 的 dataset 读到 flex 的 datagrid
flex 端:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService wsdl="http://localhost/flexService/Service1.asmx?wsdl" id="ws1">
<mx:operation name="sqlcheck" result="ResultHandler()" >
<mx:request>
<sql>{sql.text}</sql>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
[Bindable]
private var asd:XML;
private function ResultHandler():void{
asd = new XML(ws1.sqlcheck.lastResult);
dg_comments.dataProvider = asd.children();
}
]]>
</mx:Script>
<mx:TextInput x="43" y="82" width="348" height="24" id="sql" text="select 分类,型号,备注 1, 备注 2 from products_detail"/>
<mx:Button x="399" y="84" label="查询" fontSize="12" click="ws1.sqlcheck.send()"/>
<mx:DataGrid x="27" y="135" width="466" height="152" id="dg_comments">
<mx:columns>
<mx:DataGridColumn headerText="分类" dataField="分类"/>
<mx:DataGridColumn headerText="型号" dataField="型号"/>
<mx:DataGridColumn headerText="备注 1" dataField="备注 1"/>
<mx:DataGridColumn headerText="备注 2" dataField="备注 2"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService wsdl="http://localhost/flexService/Service1.asmx?wsdl" id="ws1">
<mx:operation name="sqlcheck" result="ResultHandler()" >
<mx:request>
<sql>{sql.text}</sql>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
[Bindable]
private var asd:XML;
private function ResultHandler():void{
asd = new XML(ws1.sqlcheck.lastResult);
dg_comments.dataProvider = asd.children();
}
]]>
</mx:Script>
<mx:TextInput x="43" y="82" width="348" height="24" id="sql" text="select 分类,型号,备注 1, 备注 2 from products_detail"/>
<mx:Button x="399" y="84" label="查询" fontSize="12" click="ws1.sqlcheck.send()"/>
<mx:DataGrid x="27" y="135" width="466" height="152" id="dg_comments">
<mx:columns>
<mx:DataGridColumn headerText="分类" dataField="分类"/>
<mx:DataGridColumn headerText="型号" dataField="型号"/>
<mx:DataGridColumn headerText="备注 1" dataField="备注 1"/>
<mx:DataGridColumn headerText="备注 2" dataField="备注 2"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
.net端:
[WebMethod]
public string sqlcheck(string sql)
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
connection.ConnectionString += Server.MapPath("product.mdb");
System.Data.OleDb.OleDbDataAdapter tempAdapter =new OleDbDataAdapter(sql,connection);
DataSet dataset = new DataSet("temp");
tempAdapter.Fill(dataset);
return dataset.GetXml();
}
public string sqlcheck(string sql)
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
connection.ConnectionString += Server.MapPath("product.mdb");
System.Data.OleDb.OleDbDataAdapter tempAdapter =new OleDbDataAdapter(sql,connection);
DataSet dataset = new DataSet("temp");
tempAdapter.Fill(dataset);
return dataset.GetXml();
}