flex3通过fluorinefx跟asp.net进行数据交互
flex部分代码如下:
mxml文件
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="fs.GetData();" fontSize="13">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
//获得数据后的处理函数
public function GetDataHandle(e:ResultEvent):void
{
//获得的数据绑定至DataGrid组件
dg.dataProvider=e.result.tables.serverInfo.initialData as Array;
}
//插入数据成功后的处理函数
public function InsertDataHandle(e:ResultEvent):void
{
//提示插入成功
Alert.show("插入数据成功");
//重新获取数据
fs.GetData();
}
]]>
</mx:Script>
<mx:Panel width="474" height="489" title="通知">
<mx:DataGrid id="dg">
<mx:columns>
<mx:DataGridColumn headerText="编号" dataField="0"/>
<mx:DataGridColumn headerText="标题" dataField="1"/>
<mx:DataGridColumn headerText="内容" dataField="2"/>
<mx:DataGridColumn headerText="发布者" dataField="3"/>
</mx:columns>
</mx:DataGrid>
<mx:Canvas width="395" height="243">
<mx:Label x="37" y="27" text="标题"/>
<mx:TextInput x="80" y="25" id="txtTitle"/>
<mx:Label x="37" y="155" text="发布者"/>
<mx:TextInput x="80" y="153" id="txtPublisher"/>
<mx:Label x="37" y="53" text="内容"/>
<mx:TextArea x="80" y="55" width="278" height="90" id="txtContent"/>
<mx:Button x="121" y="198" label="添加" id="btnInsert" click="fs.InsertData(txtTitle.text,txtContent.text,txtPublisher.text);"/>
</mx:Canvas>
</mx:Panel>
<mx:RemoteObject
destination="fluorine"
id="fs"
source="remoting.GetSQLServer2000Data"
showBusyCursor="true"
>
<mx:method
name="GetData"
result="GetDataHandle(event)"
/>
<mx:method
name="InsertData"
result="InsertDataHandle(event)"
/>
</mx:RemoteObject>
</mx:Application>
flex里的services_config.xml这个文件是一个配置文件就好比asp.net里的webconfig意思差不多吧都是xml结构,这个文件要跟mxml文件放在一个路径下文件内容如下:
<?xml version="1.0" encoding="UTF-8"?> <services-config> <services> <service id="remoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> <destination id="fluorine"> <channels> <channel ref="my-amf"/> </channels> <properties> <source>*</source> </properties> </destination> </service> </services> <channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> <endpoint uri="http://localhost:6199/WebSite2/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/> </channel-definition> </channels> </services-config>
好了到现在为止flex部分的文件已经完全展现给大家了.
下面是asp.net部分
首先确定在机器里已经安装了fluorinefx,现在fluorinefx已经可以支持在vs2008中使用了
打开vs2008或vs2005以后在就会出现一个fluorinefx的选项,建立好以后就可以通过修改cs代码来实现连接数据库的功能
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;//引用“System.Data.SqlClient”
using System.Collections;//引用“System.Collections”
using FluorineFx.Management.Web;
using FluorineFx;
/// <summary>
/// GetSQLServer2000Data 的摘要说明
/// </summary>
namespace remoting //名称空间,可自定义
{
[RemotingService()]
public class GetSQLServer2000Data
{
public GetSQLServer2000Data()
{
}
public DataSet GetData()//获得数据库数据
{
SqlConnection conn = new SqlConnection();//定义“SqlConnnection”类实例
//数据库连接字符串
conn.ConnectionString = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=sa";
//定义“SqlCommand”实例,从“Notes”表中取数据
SqlCommand command = new SqlCommand("select * from Notes", conn);
conn.Open();//打开连接
SqlDataAdapter da = new SqlDataAdapter();//定义“SqlDataAdapter”类实例
da.SelectCommand = command;//将“command”值传递给“SqlDataAdapter”的“SelectCommand”属性
DataSet ds = new DataSet();//定义“DataSet”类实例
da.Fill(ds, "tables");//取数据
//关闭数据库
conn.Close();
return ds;
}
public void InsertData(string title, string content, string publisher)//插入数据
{
SqlConnection conn = new SqlConnection();//定义“SqlConnnection”类实例
//数据库连接字符串
conn.ConnectionString = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=sa";
SqlCommand command = new SqlCommand("select Max(noteId) from Notes", conn);
conn.Open();//打开连接
SqlDataAdapter da = new SqlDataAdapter();//定义“SqlDataAdapter”类实例
da.SelectCommand = command;//将“command”值传递给“SqlDataAdapter”的“SelectCommand”属性
DataSet ds = new DataSet();//定义“DataSet”类实例
da.Fill(ds, "tables");//取数据
string newid = (Convert.ToInt32(ds.Tables["tables"].Rows[0][0].ToString()) + 1).ToString();
command = new SqlCommand("insert into Notes values('" + newid + "','" + title.Trim() + "','" + content.Trim() + "','" + publisher.Trim() + "')", conn);
command.ExecuteNonQuery();
conn.Close();
}
}
}
转载于:https://www.cnblogs.com/lindayyh/archive/2009/03/30/1425471.html
flex3通过fluorinefx跟asp.net进行数据交互相关推荐
- ASP.Net中关于WebAPI与Ajax进行跨域数据交互时Cookies数据的传递
本文主要介绍了ASP.Net WebAPI与Ajax进行跨域数据交互时Cookies数据传递的相关知识.具有很好的参考价值.下面跟着小编一起来看下吧 前言 最近公司项目进行架构调整,由原来的三层架构改 ...
- asp.net 应用数据缓存 -- Cache对象使用
ASP.NET 应用数据缓存 -- Cache对象使用 [原文:http://msdn.microsoft.com/zh-cn/library/18c1wd61%28v=vs.100%29.aspx] ...
- [转]asp.net导出数据到Excel的三种方法
原文出处:asp.net导出数据到Excel的几种方法(1/3) .asp.net导出数据到Excel的几种方法(2/3).asp.net导出数据到Excel的几种方法(3/3) asp.net导出到 ...
- LayIM 3.9.1与ASP.NET SignalR实现Web聊天室快速入门(七)之LayIM与MVC数据交互实现单聊和群聊
前言 本系列文章特点:使用ASP.NET SignalR和LayIM快速入门对接,实现一对一聊天,群聊,添加聊天群组,查找聊天记录等功能.源代码不包含LayIM的源代码,因为官方并没开源属于收费资源, ...
- 巧用ASP实现Web数据统计、报表和打印 (转)
巧用ASP实现Web数据统计.报表和打印 (转)[@more@] 巧用ASP实现web数据统计.报表和打印XML:namespace prefix = o ns = "urn:schemas ...
- ASP生成JSON数据
原文地址为: ASP生成JSON数据 < %@LANGUAGE = " VBSCRIPT " CODEPAGE = " 65001 " % > & ...
- ASP导入Excel数据提示:外部数据库驱动程序(1)中的意外错误 解决办法
ASP导入Excel数据提示:外部数据库驱动程序(1)中的意外错误 解决办法 最近拿起很久以前写的ASP导入excel数据程序测试时,发现好好的程序出现运行问题,之前都是好好的.真是怪事. 怎么 ...
- ASP批量更新数据代码
ASP批量更新数据代码 %> 两个文件 ..cn.asp 连接数据库用的 ..cn3.asp 执行文件 . cn.asp 源代码 <% dim conn dim dbpath bb=&qu ...
- asp后台调用产品数据_后台产品经理,需掌握这些数据交互知识
人们每天都在接收信息和发送信息,在传递信息的过程中,明白对方要表达的意思.数据也是如此,在系统交换数据的过程中,就伴随着数据交互.本篇文章将为大家具体分析前端和后台的数据交互与协议. 本文所说的&qu ...
最新文章
- python文本分析
- 亚马逊员工流动率150%,每8个月相当于“大换血”,网友:贝佐斯不知足
- SAP Spartacus ConfigInitializerService里的isStable属性
- 《React源码解析》系列完结!
- Redis启动的三种方式
- deepin安装zsh以及简单配置
- VMware Linux 共享文件夹 虚拟机无共享文件解决方法
- DSP28335 Flash烧写
- Idea中常用的快捷键(持续更新)
- 常平计算机培训班,东莞常平十大CAD培训班排名(如何为初学者学习CAD)
- 电路串联和并联图解_串联和并联的电路图怎么画
- 5.13 利用图层的矢量蒙版打造浪漫情调 [原创Ps教程]
- C语言总结(一维数组、二维数组、字符数组和字符串)
- python梯形公式面积_算法(一)梯形近似法求曲线面积
- 小程序与bmob后端云
- 「链节点活动年度总结」2019年区块链行业会议回顾
- 34、CSS高频前端面试题之CSS基础
- 3.HTML段落、文本格式化、链接
- 单页双曲面 matlab,在matlab中画函数(x^2+y^2)/9-z^2/4=1的旋转单叶双曲面
- webpack打包工具的基本使用