我有一个选择语句,可以查询获得高分的前5名球员
selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
selectStmt.text="SELECT name, level, score FROM highscores WHERE ROWID <=5 ORDER BY score DESC";
selectStmt.execute();
我希望标签中显示的名称,级别和分数。如何在标签中传递结果?
答案 0 :(得分:0)
你必须:
SQLEvent.RESULT
selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
selectStmt.text="SELECT name, level, score FROM highscores WHERE ROWID <=5 ORDER BY score DESC";
// Create a listener in order to process the results
var resultHandler:Function = function(event:SQLEvent):void {
selectStmt.removeEventListener(SQLEvent.RESULT, resultHandler);
// Get the result
var result:SQLResult = dbStatement.getResult();
if (result != null) {
// Iterate through each entries
for each (var entry:Object in result.data) {
// Trace entry
trace(entry.name, entry.level, entry.score);
}
}
};
// Add a listener in order to read the results when the request will be done
selectStmt.addEventListener(SQLEvent.RESULT, resultHandler);
selectStmt.execute();