[Flex] flex與asp.net資料交換__.net

來源:互聯網
上載者:User
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:2016/Service/Service.asmx?wsdl" id="ws1"> <mx:operation name="sqlcheck" result="ResultHandler()" >     <mx:request>         <sql>{sqlstring.text}</sql>     </mx:request> </mx:operation> </mx:WebService> <mx:WebService wsdl="http://localhost:2016/Service/Service.asmx?wsdl" id="query">         <mx:operation name="queryliuyan">                 <mx:request>                         <info>                                 {nameInput.text,titleInput.text,contentInput.text}                         </info>                 </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);                 datetest.dataProvider = asd.children();                 title1.text = asd..title[1];                 name1.text = asd..name[1];                 date1.text = asd..date[1];                 content1.text = asd..content[1];                             }     ]]> </mx:Script>         <mx:DataGrid x="47" y="26" id="datetest">                 <mx:columns>                         <mx:DataGridColumn headerText="主題" dataField="title"/>                         <mx:DataGridColumn headerText="作者" dataField="name"/>                         <mx:DataGridColumn headerText="日期" dataField="date"/>                         <mx:DataGridColumn headerText="內容" dataField="content"/>                 </mx:columns>         </mx:DataGrid>         <mx:Label  id="sqlstring" x="226" y="428" text="select title,name,date,content from liuyan"/>         <mx:Button x="466" y="25" label="查詢" fontSize="12" click="ws1.sqlcheck.send();"/>         <mx:Label x="529" y="95" text="Label" id="title1" fontSize="14"/>         <mx:Label x="529" y="130" text="Label" id="name1" fontSize="14"/>         <mx:Label x="529" y="167" text="Label" id="date1" fontSize="14"/>         <mx:Label x="529" y="205" text="Label" id="content1" fontSize="14"/> </mx:Application>  net代碼

using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Data.OleDb; using System.Collections; using System.Data; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService {     public Service () {         //如果使用設計的組件,請取消注釋以下行          //InitializeComponent();      }     [WebMethod]//直接顯示在datagrid中     public string sqlscan(string sql)     {         OleDbConnection connection = new OleDbConnection();         connection.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=";         connection.ConnectionString += Server.MapPath("user.mdb");         System.Data.OleDb.OleDbDataAdapter liuyan = new OleDbDataAdapter(sql, connection);         DataSet dataset1 = new DataSet("test");         liuyan.Fill(dataset1);         return dataset1.GetXml();     }     [WebMethod]//這個才是串連資料庫並顯示在label中     public string sqlcheck(string sql)     {         OleDbConnection connection = new OleDbConnection();         connection.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";         connection.ConnectionString += Server.MapPath("user.mdb");         System.Data.OleDb.OleDbDataAdapter tempAdapter = new OleDbDataAdapter(sql, connection);         DataSet dataset = new DataSet("temp");         tempAdapter.Fill(dataset);         return dataset.GetXml();     } }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.