0

I have a select statement that queries the top 5 players who got high scores

selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;            
selectStmt.text="SELECT name, level, score FROM highscores WHERE ROWID <=5 ORDER BY score DESC";        
selectStmt.execute();

I want the name, level, and score displayed in labels. How can I pass the results in labels?

4

1 回答 1

0

你必须:

  1. SQLEvent.RESULT
  2. 执行您的查询
  3. 处理结果
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();
于 2012-09-04T09:58:38.340 回答