加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex调用webService读取SQL数据库

发布时间:2020-12-15 04:11:41 所属栏目:百科 来源:网络整理
导读:算不上是原创,而是根据别人的结合自己修改的,学习之用 webService的方法 ?[WebMethod] ????????? public? DataTable func() ??????? { ??????????? String strconn = "Server=本人的ip或者是.;database=XC0505;user=sa;password=123"; ??????????? SqlConn

算不上是原创,而是根据别人的结合自己修改的,学习之用

webService的方法

?[WebMethod]
????????? public? DataTable func()
??????? {
??????????? String strconn = "Server=本人的ip或者是.;database=XC0505;user=sa;password=123";
??????????? SqlConnection cn = new SqlConnection(strconn);
??????????? //cn.Open();
??????????? //SqlCommand cm = new SqlCommand("select * from TRUEMAP_CROSSING",cn);
??????????? //SqlDataReader dr = cm.ExecuteReader();?

??????????? //dg.DataSource = dr;????????????如果只是在aspx中显示,这样就行,跟Flex中绑定不同
??????????? //dg.DataBind();
??????????? //cn.Close();
???????????

?

????????? ??//? SqlDataAdapter sda = new SqlDataAdapter("select * from TRUEMAP_CROSSING",cn);
??????????? //DataSet ds = new DataSet();
??????????? //sda.Fill(ds);
??????????? //DataTable table = ds.Tables[0];
??????????? //dg.DataSource = table;
??????????? //dg.DataBind();?????????????????????????????????????????????? //如果只是在aspx中显示这样也行

?

??????????? SqlDataAdapter sda = new SqlDataAdapter("select * from TRUEMAP_CROSSING",cn);???????? //这句以后是将查询的数据作为一个表来返回,c#的跟Flex是有区别的
??????????? DataSet ds = new DataSet();??????
??????????? sda.Fill(ds);
??????????? DataTable table = ds.Tables[0];
??????????? return table;

????? }

Flex端的代码:

???public function init():void
???{
//????myWebservice.addEventListener(ResultEvent.RESULT,onSuccess);
//????myWebservice.addEventListener(FaultEvent.FAULT,onFault);
??????this.myWebservice.func();??????????????//func为服务端方法名称
???}
???public function onSuccess(event:ResultEvent):void???????????????????????//调用成功执行的方法
???{
????/* dg.dataProvider=this.myWebservice.func.lastResult.Tables.Table.Rows; */??????????????????//这句也可以写在下面???
???}
???public function onDefault(event:FaultEvent):void???
???{
????Alert.show("Error");
????
???}
??]]>
?</fx:Script>
?<s:layout>
??<s:BasicLayout/>
?</s:layout>
?<fx:Declarations>
??<!-- 将非可视元素(例如服务、值对象)放在此处 -->
??<s:WebService id="myWebservice" wsdl=" http://xxx/gaga/Service1.asmx?WSDL">? ??</s:WebService> ?</fx:Declarations> ? ?<mx:DataGrid id="dg" width="100%" height="100%" dataProvider="{this.myWebservice.func.lastResult.Tables.Table.Rows}"> ??<mx:columns> ???<mx:DataGridColumn headerText="LinkGuid" dataField="LinkGuid"/>????//要显示的字段,按列显示 ???<mx:DataGridColumn headerText="NodeGuid" dataField="NodeGuid"/> ???<mx:DataGridColumn headerText="ToWard" dataField="ToWard"/> ???<mx:DataGridColumn headerText="RoadName" dataField="RoadName"/> ??</mx:columns> ?</mx:DataGrid>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读