如何在动作脚本 3.0 和 flex 中使用循环将动态数组中的数据插入到从 WebService 获取的 sqlite db [英] How to insert data from dynamic array to sqlite db getting from WebService Using Loop in action script 3.0 and flex

查看:12
本文介绍了如何在动作脚本 3.0 和 flex 中使用循环将动态数组中的数据插入到从 WebService 获取的 sqlite db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Webservice 调用成功时使用 Loop 将动态数组插入数据库

首先是我绑定到 DataGrid 的 Web 服务

first my Webservice which i have Bind to DataGrid

<fx:Declarations>

        <mx:WebService 
            id="ws" 
            wsdl="http://localhost:2690/vtrServices.asmx?wsdl"> 
        </mx:WebService>

        <vtrservices:VtrServices id="vtrServices"
                                 fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
                                 showBusyCursor="true"
                                 result="vtrServices_resultHandler(event)"
                                 />

        <s:CallResponder id="SignIn1Result2"/>
        <s:CallResponder id="GetMyTasksNew1Result"
                     result="GetMyTasksNew1Result_resultHandler(event)"/>


    </fx:Declarations>

当我在函数的帮助下单击我的登录按钮时调用此 WebService

This WebService Is called when i clicked on my Loging Button with the help Of the function

<mx:Button label="Login" id="btnLogin" click="Login();"/>

我的 Login() 函数是

My Login() FUnction is

private function Login():void {
                // Get Data from WebService and fill datagrid when you fist invoke the application
                SignIn1Result2.token = vtrServices.SignIn1(txtUserName.text, txtPassword.text);
                stmt.sqlConnection = this.isDbConnected(conn);
        }

结果事件中,我调用了另一种网络服务方法

protected function vtrServices_resultHandler(event:ResultEvent):void
            {
                // TODO Auto-generated method stub
                InsertUser(SignIn1Result2.lastResult[0].UserId,SignIn1Result2.lastResult[0].UserName,SignIn1Result2.lastResult[0].ContactName,SignIn1Result2.lastResult[0].Password);
                UserLogin.visible= false;
                GetMyTasksNew1Result.token = ws.GetMyTasksNew1(SignIn1Result2.lastResult[0].UserId);
            }

InsertUser 函数的定义是

private function InsertUser(UserId:String, UserName:String,ContactName:String, Password:String):void
        {
            stmt.sqlConnection = this.isDbConnected(conn);
            stmt.text = "INSERT OR REPLACE INTO TblUsers (UserId, UserName, ContactName ,Password) VALUES('"+UserId+"','"+UserName+"','"+ContactName+"','"+Password+"');";  
            stmt.execute();
            stmt1.sqlConnection = this.isDbConnected(conn);
            stmt1.text = "CREATE TABLE IF NOT EXISTS TblTasks (TaskId INTEGER PRIMARY KEY, AssignmentId INTEGER, ProjectId INTEGER,TeamId INTEGER,AssigneeName Varchar(100),Priority Varchar(15),ActualStartTime DATETIME,ActualEndTime DATETIME,Progress INTEGER);";
            stmt1.execute();

}

我正在做的以下过程插入到我的数据库中,但出现错误,只有从 WebService 返回的第一行被插入到表中

The Following process i am doing To insert into my db but there is an error , Only First Row returned from the WebService is Inserted into Table

protected function GetMyTasksNew1Result_resultHandler(event:ResultEvent):void
            {
                stmt2.sqlConnection = this.isDbConnected(conn);         
                 //Alert.show(GetMyTasksNew1Result.lastResult[2].TaskId.toString());
                 for(var i:int=0;i<=GetMyTasksNew1Result.lastResult.length-1;i++)
                {  
                Alert.show(GetMyTasksNew1Result.lastResult[i].TaskId.toString());
                stmt2.text = "Insert OR REPLACE INTO TblTasks (TaskId, AssignmentId , ProjectId ,TeamId ,AssigneeName ,Priority ,ActualStartTime ,ActualEndTime ,Progress ) Values('"+GetMyTasksNew1Result.lastResult[i].TaskId+"','"+GetMyTasksNew1Result.lastResult[i].AssignmentId+"','"+GetMyTasksNew1Result.lastResult[i].ProjectId+"','"+GetMyTasksNew1Result.lastResult[i].TeamId+"', '"+GetMyTasksNew1Result.lastResult[i].AssigneeName+"','"+GetMyTasksNew1Result.lastResult[i].Priority+"','"+GetMyTasksNew1Result.lastResult[i].StartTime+"', '"+GetMyTasksNew1Result.lastResult[i].EndTime+"','"+GetMyTasksNew1Result.lastResult[i].Progress+"');"; 
                stmt2.execute(); 
                 } 



            }

            ![Data i want to insert it is dynamic for every User][1]

但是我在与 For 循环中的 Sql 执行相关的 CallResponder 的成功事件中遇到错误

but i am getting errors while In the SUccess Event of the CallResponder Related to the Sql Execution In For Loop

谁能帮我将数组插入数据库...记住我的数组是动态的我在这里描述的函数的正确顺序...如果有人能帮我插入到表中在本地数据库中使用 Forloop .

Could anyone help me to insert the Array to Database ... Remember my Array is dynamic The proper Sequence of the functions i have discribed here ... if anybody can help me to Insert Into Table in local database Using Forloop .

任何帮助都会受到极大的赞赏..谢谢..

Any Help Will be greatly Admired .. Thanks..

推荐答案

我的代码完全正确,但在调用数据库时犯了一个愚蠢的错误.
我只是改变了调用方式

My code was absolutely Right but a silly mistake done while calling the Database .
I just changed the call method

conn.openAsync(db);conn.open(db); 并且它工作了

conn.openAsync(db); To conn.open(db); And it worked

    private function dbinit(event:Event):void
            {
                var dir:File = File.applicationDirectory;
                //
                var db:File = dir.resolvePath("dbImthePM.db");
                // after we set the file for our database we need to open it with our SQLConnection.

                conn.open(db);
/*              conn.openAsync(db); */ //Earlier It was Not letting me to reuse the sql statments
                //We set event listeners to check that the database is opened
                //The second event listener is to catch any processing errors
                //The last is handle the results from our queries since
                //Actionscript is an event based language.
                conn.addEventListener(SQLEvent.OPEN, dbLoaded);
                conn.addEventListener(SQLErrorEvent.ERROR, sqlError);
                conn.addEventListener(SQLEvent.RESULT, sqlResult);
            } 

感谢 http://www.linkedin.com/in/tomvandeneynde

这篇关于如何在动作脚本 3.0 和 flex 中使用循环将动态数组中的数据插入到从 WebService 获取的 sqlite db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆