PDA

View Full Version : Deleting a column from a datgrid


flexable
06-01-2010, 08:30 PM
The program is running fine bt nt able to select the column n delete it...i hav written the delet()......n pointed out where i gt the error......it says undefined property employees.


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.data.SQLConnection;
import flash.events.SQLErrorEvent;
import flash.data.SQLStatement;
import flash.events.SQLEvent;
import flash.filesystem.File;
import mx.collections.ArrayCollection;

[Bindable]

// main function connection object creation
private var conn:SQLConnection = new SQLConnection();
private function init():void
{

var dbFile:File = File.applicationStorageDirectory.resolvePath("Sample.db");
conn.open(dbFile);
var createStmt:SQLStatement = new SQLStatement();
createStmt.sqlConnection = conn;
var sql:String =
"CREATE TABLE IF NOT EXISTS EMPLOYEES ( EMPLOYEE_ID INTEGER PRIMARY KEY AUTOINCREMENT ,F_NAME TEXT,L_NAME TEXT)";
createStmt.text = sql;
createStmt.execute();

}

// select function

private function select():void
{

var selectStmt:SQLStatement = new SQLStatement();
selectStmt.sqlConnection = conn;

selectStmt.text = "SELECT * FROM EMPLOYEES";

selectStmt.execute();
dg.dataProvider=selectStmt.getResult().data;


}

// insert fuction
private function insert():void
{

var insertStmt:SQLStatement = new SQLStatement();
insertStmt.sqlConnection = conn;
var sqls:String = "INSERT INTO EMPLOYEES (F_NAME , L_NAME) VALUES(?,?)";
insertStmt.parameters[0] = fname.text;
insertStmt.parameters[1] = lname.text;
insertStmt.text = sqls;
insertStmt.execute();

select();
}

// delete function
private function delet():void
{

var Stmt:SQLStatement = new SQLStatement();
Stmt.sqlConnection = conn;
Stmt.text = "DELETE FROM EMPLOYEES WHERE EMPLOYEE_ID= ?";
error//Stmt.parameters[0]=employees.selectedItem.EMPLOYEE_ID;
Stmt.execute();
select();

}

]]>
</mx:Script>
<mx:TextInput x="75" y="61" id="fname" />
<mx:TextInput x="260" y="61" id="lname"/>
<mx:DataGrid x="75" y="107" id="dg" width="345">
<mx:columns>
<mx:DataGridColumn headerText="firstname" dataField="F_NAME"/>
<mx:DataGridColumn headerText="lastname" dataField="L_NAME"/>

</mx:columns>
</mx:DataGrid>
<mx:Button x="474" y="61" id="b1" label="insert" click="insert()"/>
<mx:Button x="474" y="124" label="delete" id="d1" click="delet()"/>

</mx:WindowedApplication>

Peter Cowling
06-01-2010, 09:44 PM
An Adobe Air question...