我想从ActionScript3连接数据库SQL2005,我需要从actionscript执行查询语句!任何人都可以告诉我请做的代码???? 我搜索了这个问题,结果没有帮助我,因为代码不起作用,所以我感到困惑。
答案 0 :(得分:1)
在adobe air中尝试此代码
import flash.display.*;
import flash.data.*;
//import flash.data.SQLSchema;
import flash.events.SQLEvent;
import flash.events.SQLErrorEvent;
import flash.data.SQLConnection;
import flash.data.SQLStatement;
import flash.errors.SQLError;
//import flash.filesystem;
var conn:SQLConnection;
var dbStatement:SQLStatement;
trace("sandeep mittal");
init();
function init():void
{
conn = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, connOpenHandler);
trace("sandeep mittal");
dbStatement = new SQLStatement();
dbStatement.sqlConnection = conn;
dbStatement.text = "SELECT id, name, ssn FROM employees";
var dbFile:File = new File(File.separator + "");
conn.open(dbFile);
}
function connOpenHandler(e:SQLEvent):void
{
trace("Sandeep Mittal");
dbStatement.addEventListener(SQLEvent.RESULT, resultHandler);
dbStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler);
dbStatement.execute();
}
function resultHandler(even:SQLEvent):void
{
var result1:SQLResult = dbStatement.getResult();
if (result1 != null)
{
var numRows:int = result1.data.length;
for (var i:int = 0; i < numRows; i++)
{
var row:Object = result1.data[i];
trace("id:", row.id, ", name:", row.name, ", ssn:", row.ssn);
}
}
}
function errorHandler(event:SQLErrorEvent):void
{
trace("An error occured while executing the statement.");
}