2013-11-25 25 views
0

正試圖創建新的記錄,我的本地sqlite數據庫使用此代碼 但它dosent工作,當我點擊保存我得到這個錯誤1067:類型值的隱式強制到一個不相關的類型flash.data:SQLConnection

1120:Access of undefined property sqlConnection.

這是我在EmployeeDAO

  public static function create(employee:Employee):void 
    { 

    var sql:String = "INSERT INTO words (id, term, defin, term1, defin1) " + 
      "VALUES (?,?,?,?,?)"; 
     var stmt:SQLStatement = new SQLStatement(); 
     stmt.sqlConnection = sqlConnection; 
     stmt.text = sql; 

     stmt.parameters[1] = employee.term; 
     stmt.parameters[2] = employee.defin; 
     stmt.parameters[3] = employee.term1; 
     stmt.execute(); 
     employee.loaded = false; 
    } 

add.mxml方法,其中我嘗試記錄保存到數據庫

import model.Employee; 
    import model.EmployeeDAO; 

     protected function onSave():void { 

      var newEmployee:Employee = new Employee(); 
      newEmployee.term = term.text; 
      newEmployee.defin = defin.text; 
      newEmployee.term1 = term1.text; 
      newEmployee.defin1 = defin1.text; 
      EmployeeDAO.create(newEmployee); 
      navigator.popView(); 
     } 
    ]]> 
</fx:Script> 

<s:actionContent> 
    <s:Button label="Save" click="onSave()"/> 
</s:actionContent> 

<s:layout> 
    <s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10"/> 
</s:layout> 

<s:Label text="term"/> 
<s:TextInput id="term" width="100%"/> 

<s:Label text="defin"/> 
<s:TextArea id="defin" width="100%" height="200"/> 

<s:Label text="term1"/> 
<s:TextInput id="term1" width="100%"/> 

<s:Label text="defin1"/> 
<s:TextArea id="defin1" width="100%" height="200"/> 

回答

0

,如果你想稱之爲沒有實例類,您應該聲明你的函數爲靜態。然後它會工作

public static function create(employee:Employee):void 
+0

我試過了,並得到了另一個錯誤檢查第一篇文章 – sayydo

+0

當然,它會給錯誤。根據你的代碼,sqlconnection沒有定義。如果您有靜態函數外定義的SqlConnection那麼它也應該被定義爲靜態的。 – Sumit

+0

但我不能確定它不止一次,已經做了「公共職能得到的SqlConnection()的SQLConnection」 – sayydo

相關問題