2014-04-24 6 views
0

어떻게삽입하는 방법 데이터는 액션 스크립트 3.0에서 루프를 사용하고 플렉스 WebService에에서 점점 DB를 sqlite를하는

먼저 Webservice를 호출의 성공에 루프를 사용하여 데이터베이스에 동적 배열을 삽입 할 수 있습니다 내 내가 데이터 그리드에 바인딩이 웹 서비스 나 기능의 도움으로 내 Loging 버튼을 클릭하면이 WebService를 호출

<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> 

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

Login() 기능은 결과 이벤트 내가 또 다른 웹 서비스 방법

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 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); 
     } 

입니다

입니다 ,451,515,
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(); 

} 난 내 DB에 삽입하고있는 중이 야하지만 오류가있는 다음과 같은 프로세스가 만 첫 행 WebService에에서 반환

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] 

에 삽입하지만 난 오류를 얻고있다 CallResponder의 성공 이벤트에 대한 루프에서 SQL 실행 관련 동안

사람은 내 배열은 동적 날 ... 가 기억 데이터베이스에 배열을 삽입하는 데 도움이 수 함수의 적절한 순서는 여기에 discribed ... 아무도 내가 Forloop을 사용하여 로컬 데이터베이스에 테이블에 삽입하는 것을 도울 수 있다면.

어떤 도움을 크게 존경 할 것인가 .. 덕분에 ..

enter image description here

답변

0

내 코드가

Screen shot values i want to insert and Error

절대적으로 오른쪽했지만 데이터베이스를 호출하는 동안 바보 같은 실수 다.
난 그냥 conn.open(db); 호출 방법

conn.openAsync(db);을 변경 그리고 http://www.linkedin.com/in/tomvandeneynde

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); 
      } 

감사했다