Comunidad de diseño web y desarrollo en internet online

Este codigo como lo hago

Citar            
MensajeEscrito el 19 Oct 2007 02:48 pm
:crap: Tengo un problema hice una aplicacion que conecta se con access por medio de zinc. todo va bien cargue los datos a un data set asi:

Código :

var BaseFile:String = "agenda.mdb";
var BasePassword:String = "";
var path:String = mdm.Application.path+BaseFile;
mdm.Database.MSAccess.connect(BaseFile, BasePassword);
var success:Boolean = mdm.Database.MSAccess.success();
if (!success) {
   mdm.Dialogs.prompt("ERROR");
   return;
}

con dos btn cargo los datos al datagrid:
[code]
//btn1//
on (press) {
mdm.Database.MSAccess.select("SELECT * FROM Usuarios_Agenda");
var myDP:Array = new Array();
var D:Array = mdm.Database.MSAccess.getData();
for (var L in D) {
myDP.addItem({id:D[L][0], Nombre:D[L][1], Apellidos:D[L][2]});
}
_parent.DataSet.Usuarios_Agenda = myDP;
}
//btn2//

[code]
on (press) {
_parent.DataGrid.dataProvider = _parent.DataSet.Usuarios_Agenda;
}
[/code]

aqui biene lo duro, intento editar el datagrid directamente le doy en propiedades editable tue y agrego este codigo:
[code]
_level0.populate.enabled=false;

listenerObject = new Object();
listenerObject.cellEdit = function(evt_obj){
var fieldName="";
if (evt_obj.columnIndex==0) {fieldName="id"}
if (evt_obj.columnIndex==1) {fieldName="Nombre"}
if (evt_obj.columnIndex==2) {fieldName="Apellidos"}
var fieldID=evt_obj.target.selectedItem["id"];
var fieldNewValue=evt_obj.target.selectedItem[fieldName];
var newQuery="UPDATE Usuarios_Agenda SET "+fieldName+" = \""+fieldNewValue+"\" WHERE id="+fieldID;
mdm.Database.MSAccess.runQuery(newQuery);
mdm.Dialogs.prompt("Row with ID:"+fieldID+" has been Updated in the Database");

}
_level0.DataGrid.addEventListener("cellEdit", listenerObject)

[/code]
esto me crea siempre un error al editar un campo lo cambia por undefinied o me crea un erro de consulta. alguien me puede ayudar con esto??

Gracias

Por Barak

78 de clabLevel



Genero:Masculino  

msie
Citar            
MensajeEscrito el 28 Nov 2010 12:11 am
Hola compadre antes que nada el codigo que creaste es de gran ayuda para DataGrid autoguardable en MDM zinc.
Retome tu codigo y logre insertar datos en tablas con id primary Key not null,

y al finalmente obtuve este codigo tenias la idea solo lo tenias revuelto.

listenerObject = new Object();
listenerObject.cellEdit = function(evt_obj){
var fieldName="";
if (evt_obj.columnIndex==0) {fieldName="idEjemplo"}
if (evt_obj.columnIndex==1) {fieldName="Nombre"}
if (evt_obj.columnIndex==2) {fieldName="Edad"}
trace(fieldName);

var fieldID = evt_obj.target.selectedItem["idEjemplo"];
var fieldNewValue = evt_obj.target.selectedItem[fieldName];
salida.text=fieldName+fieldID+fieldNewValue;
var newQuery="UPDATE Ejemplo SET "+fieldName+" = \""+fieldNewValue+"\" WHERE idEjemplo="+fieldID;
mdm.Database.MySQL.runQuery(newQuery);
mdm.Dialogs.prompt("Row with ID:"+fieldID+" has been Updated in the Database");
}
theDataGrid.addEventListener("cellEdit", listenerObject)

En mi caso mi tabla se llama ejemplo con 3 campos idEjemplo,Nombre y Edad
salida.text es un textbox de salida y con esto pude actualizar automaticamente el datagrid Gracias por el codigo,
mi conexion es con una base de datos MySQL.


Saludos a la comunidad Cristal Lab.

Por CLAnonimo

Claber

600 de clabLevel

5 tutoriales
1 articulo

 

Este es un usuario anónimo genérico para las cuentas borradas o perdidas.

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.