[Flex] flex與asp.net數據交換

flex 代碼:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3. <mx:WebService wsdl="http://localhost:2016/Service/Service.asmx?wsdl" id="ws1">
  4. <mx:operation name="sqlcheck" result="ResultHandler()" >
  5.     <mx:request>
  6.         <sql>{sqlstring.text}</sql>
  7.     </mx:request>
  8. </mx:operation>
  9. </mx:WebService>
  10. <mx:WebService wsdl="http://localhost:2016/Service/Service.asmx?wsdl" id="query">
  11.         <mx:operation name="queryliuyan">
  12.                 <mx:request>
  13.                         <info>
  14.                                 {nameInput.text,titleInput.text,contentInput.text}
  15.                         </info>
  16.                 </mx:request>
  17.         </mx:operation>
  18. </mx:WebService>
  19. <mx:Script>
  20.     <![CDATA[
  21.         import mx.rpc.events.ResultEvent;
  22.             [Bindable]
  23.             private var asd:XML;
  24.             private function ResultHandler():void{
  25.                 asd = new XML(ws1.sqlcheck.lastResult);
  26.                 datetest.dataProvider = asd.children();
  27.                 title1.text = asd..title[1];
  28.                 name1.text = asd..name[1];
  29.                 date1.text = asd..date[1];
  30.                 content1.text = asd..content[1];
  31.                
  32.             }
  33.     ]]>
  34. </mx:Script>
  35.         <mx:DataGrid x="47" y="26" id="datetest">
  36.                 <mx:columns>
  37.                         <mx:DataGridColumn headerText="主題" dataField="title"/>
  38.                         <mx:DataGridColumn headerText="作者" dataField="name"/>
  39.                         <mx:DataGridColumn headerText="日期" dataField="date"/>
  40.                         <mx:DataGridColumn headerText="內容" dataField="content"/>
  41.                 </mx:columns>
  42.         </mx:DataGrid>
  43.         <mx:Label  id="sqlstring" x="226" y="428" text="select title,name,date,content from liuyan"/>
  44.         <mx:Button x="466" y="25" label="查詢" fontSize="12" click="ws1.sqlcheck.send();"/>
  45.         <mx:Label x="529" y="95" text="Label" id="title1" fontSize="14"/>
  46.         <mx:Label x="529" y="130" text="Label" id="name1" fontSize="14"/>
  47.         <mx:Label x="529" y="167" text="Label" id="date1" fontSize="14"/>
  48.         <mx:Label x="529" y="205" text="Label" id="content1" fontSize="14"/>
  49. </mx:Application>
 net代碼

  1. using System;
  2. using System.Web;
  3. using System.Web.Services;
  4. using System.Web.Services.Protocols;
  5. using System.Data.OleDb;
  6. using System.Collections;
  7. using System.Data;
  8. [WebService(Namespace = "http://tempuri.org/")]
  9. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  10. public class Service : System.Web.Services.WebService
  11. {
  12.     public Service () {
  13.         //如果使用設計的組件,請取消註釋以下行 
  14.         //InitializeComponent(); 
  15.     }
  16.     [WebMethod]//直接顯示在datagrid中
  17.     public string sqlscan(string sql)
  18.     {
  19.         OleDbConnection connection = new OleDbConnection();
  20.         connection.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=";
  21.         connection.ConnectionString += Server.MapPath("user.mdb");
  22.         System.Data.OleDb.OleDbDataAdapter liuyan = new OleDbDataAdapter(sql, connection);
  23.         DataSet dataset1 = new DataSet("test");
  24.         liuyan.Fill(dataset1);
  25.         return dataset1.GetXml();
  26.     }
  27.     [WebMethod]//這個纔是連接數據庫並顯示在label中
  28.     public string sqlcheck(string sql)
  29.     {
  30.         OleDbConnection connection = new OleDbConnection();
  31.         connection.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
  32.         connection.ConnectionString += Server.MapPath("user.mdb");
  33.         System.Data.OleDb.OleDbDataAdapter tempAdapter = new OleDbDataAdapter(sql, connection);
  34.         DataSet dataset = new DataSet("temp");
  35.         tempAdapter.Fill(dataset);
  36.         return dataset.GetXml();
  37.     }
  38. }


發佈了15 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章