2013-11-25 26 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

相关问题