我正在尝试使用此代码为我的本地sqlite数据库创建新记录 但它有效,当我点击保存我得到这个错误
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 :(得分:0)
如果要在不实例化类的情况下调用它,则应将函数声明为static。然后它会工作
public static function create(employee:Employee):void