dragonzoebai的专栏

菜鸟学编程

flex调用webservice中的datatable结果写入datagrid

webservice配置文件

<appSettings>
		<add key="sqlConDuke" value="server=10.9.34.88;database=PanoSalado;uid=sa;pwd=123"/>
	</appSettings>
Webservice代码

 //测试数据库连接
    [WebMethod(Description = "!!!测试数据库连接,链接字符串在web.config中")]
    public bool conectDB()
    {
        strCon = ConfigurationSettings.AppSettings["sqlConDuke"];
        conn = new SqlConnection(strCon);
        try
        {
            conn.Open();
            return true;
        }
        catch (Exception)
        {
            return false;
        }
        finally
        {
            conn.Close();
        }
    }

    [WebMethod(Description = "!!!获得所有数据(DataTable),strTb,eg:PanView")]
    public DataTable getAllDT(string strTb)
    {
        bool ifCon = conectDB();
        if (ifCon)
        {
            string sql_BfCar = "SELECT * FROM " + strTb;
            da = new SqlDataAdapter(sql_BfCar, conn);
            myds = new DataSet();
            da.Fill(myds);
            mydt=myds.Tables[0];
            return mydt;
        }
        else
        {
            return null;
        }
    }

Flex代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Script>
		<![CDATA[ 
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

			[Bindable]
			public var arr:ArrayCollection=new ArrayCollection();
			
			protected function button1_clickHandler(event:MouseEvent):void
			{
				myWeb.getAllDT("PanView"); //分别为webservice中的方法和参数
			}
			internal function onSuccess(evt:ResultEvent):void
			{
				 arr=this.myWeb.getAllDT.lastResult.Tables.Table.Rows; //Table为webservice中的datatable名字
				 Alert.show(arr.length.toString());
			}

			protected function button2_clickHandler(event:MouseEvent):void
			{
				myWeb.getLinkDTByImgName("PanView","20131019072740-0000150");
			}
			internal function onSuccess1(evt:ResultEvent):void
			{
				arr=this.myWeb.getLinkDTByImgName.lastResult.Tables.Table.Rows;
				Alert.show(arr.length.toString());
			}
			
			internal function onFault(evt:FaultEvent):void
			{
				Alert.show("调用WebService方法失败,详细:" + evt.fault.faultDetail.toString());
			}

		]]>
	</fx:Script>
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:WebService id="myWeb" wsdl="http://10.19.1.55/serverPano/WebServiceDuke.asmx?WSDL" fault="onFault(event)">
			<s:operation name="getAllDT" result="onSuccess(event)"></s:operation>
			<s:operation name="getLinkDTByImgName" result="onSuccess1(event)"></s:operation>
		</s:WebService>
	</fx:Declarations>
	<mx:DataGrid x="121" y="177" width="737" height="402" id="dg1" dataProvider="{arr}"> 
		<mx:columns>
			<mx:DataGridColumn headerText="ID" dataField="ID"/> <!--webservice中datatable中的字段-->
			<mx:DataGridColumn headerText="ImageName" dataField="ImageName"/>
			<mx:DataGridColumn headerText="LinkGuid" dataField="LinkGuid"/>
		</mx:columns>
	</mx:DataGrid>
	<s:Button x="254" y="82" label="返回所有" click="button1_clickHandler(event)"/>
	<s:Button x="500" y="82" label="按照片名查询" click="button2_clickHandler(event)"/>
</s:Application>













阅读更多
个人分类: flex C#
想对作者说点什么? 我来说一句

Flex调用webService

2010年02月24日 656KB 下载

没有更多推荐了,返回首页

不良信息举报

flex调用webservice中的datatable结果写入datagrid

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭