Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Dataset not in edit or insert mode (https://www.clubdelphi.com/foros/showthread.php?t=78695)

ErYcK 10-05-2012 12:53:26

Dataset not in edit or insert mode
 
Buenas a todos, mi problema es el siguiente:
Trabajo con c++ Builder 6 y Access 2007
Mi aplicación se encarga de cargar un archivo .csv en un StringGrid mediante un boton al que llamo Importar, hasta ahi todo bien, una vez cargado este archivo, intento que los datos de este StringGrid se guarden en la base de datos que tengo en acces lo hago de la siguiente forma:

Código:

XDatos->TCategorias->Open();

        XDatos->TSubCat1->Open();

        XDatos->TSubCat2->Open();

        XDatos->TSubCat3->Open();

        XDatos->TMarcas->Open();


        XDatos->TCaracteristicas->Open();

        for (int f=1;f<=StringGrid1->RowCount;f++)
        {

                if (StringGrid1->Cells[0][f]!="")
                {

                        XDatos->QProductos->Append();
                        XDatos->QProductosREFERENCIA->Value = StringGrid1->Cells[0][f];
                        XDatos->QProductosESTADO->Value = StringGrid1->Cells[1][f];
                        //XDatos->QProductosCATEGORIA->Value = StringGrid1->Cells[2][f];
                        bool esta=false;
                        while(!XDatos->TCategorias->Eof)
                        {
                                if (StringGrid1->Cells[2][f] == XDatos->TCategoriasCATEGORIA->Value)
                                {
                                        XDatos->QProductosCATEGORIA->Value=XDatos->TCategoriasCodCategoria->Value;
                                        esta=true;
                                }
                                XDatos->TCategorias->Next();
                        }
                        if (!esta)
                        {
                                XDatos->TCategorias->Append();
                                XDatos->TCategoriasCATEGORIA->Value = StringGrid1->Cells[2][f];
                                XDatos->QProductosCATEGORIA->Value=XDatos->TCategoriasCodCategoria->Value;
                                XDatos->TCategorias->Post();

                        }
                        //XDatos->QProductosSUBCAT1->Value = StringGrid1->Cells[3][f];
                        esta=false;
                        while(!XDatos->TSubCat1->Eof)
                        {
                                if (XDatos->TSubCat1CATEGORIA->Value == XDatos->QProductosCATEGORIA->Value && XDatos->TSubCat1SUBCAT1->Value == StringGrid1->Cells[3][f])
                                {
                                        XDatos->QProductosSUBCAT1->Value= XDatos->TSubCat1CodSUBCAT1->Value;
                                        esta=true;
                                }
                                XDatos->TSubCat1->Next();
                        }
                        if (!esta)
                        {


                                //XDatos->TSubCat1CodSUBCAT1->Value = XDatos->QProductosSUBCAT1->Value;
                                XDatos->TSubCat1->Append();
                                XDatos->TSubCat1SUBCAT1->Value = StringGrid1->Cells[3][f];
                                XDatos->TSubCat1CATEGORIA->Value = XDatos->QProductosCATEGORIA->Value;
                                XDatos->QProductosSUBCAT1->Value= XDatos->TSubCat1CodSUBCAT1->Value;
                                XDatos->TSubCat1->Post();

                        }
                        //XDatos->QProductosSUBCAT2->Value = StringGrid1->Cells[4][f];
                        esta=false;
                        while(!XDatos->TSubCat2->Eof)
                        {
                                if (XDatos->TSubCat2SUBCAT1->Value == XDatos->QProductosSUBCAT1->Value && XDatos->TSubCat2SUBCAT2->Value == StringGrid1->Cells[4][f])
                                {
                                        XDatos->QProductosSUBCAT2->Value = XDatos->TSubCat2CodSUBCAT2->Value;
                                        esta=true;
                                }
                                XDatos->TSubCat2->Next();
                        }
                        if (!esta)
                        {


                                //XDatos->TSubCat2CodSUBCAT2->Value = XDatos->QProductosSUBCAT2->Value;
                                XDatos->TSubCat2->Append();
                                XDatos->TSubCat2SUBCAT2->Value = StringGrid1->Cells[4][f];
                                XDatos->TSubCat2SUBCAT1->Value = XDatos->QProductosSUBCAT1->Value;
                                XDatos->QProductosSUBCAT2->Value = XDatos->TSubCat2CodSUBCAT2->Value;
                                XDatos->TSubCat2->Post();
                        }
                        //XDatos->QProductosSUBCAT3->Value = StringGrid1->Cells[5][f];
                        esta=false;
                        while(!XDatos->TSubCat3->Eof)
                        {
                                if (XDatos->TSubCat3SUBCAT2->Value == XDatos->QProductosSUBCAT2->Value && XDatos->TSubCat3SUBCAT3->Value == StringGrid1->Cells[5][f])
                                {
                                        XDatos->QProductosSUBCAT3->Value = XDatos->TSubCat3CodSUBCAT3->Value;
                                        esta=true;
                                }
                                XDatos->TSubCat3->Next();
                        }
                        if (!esta)
                        {


                                //XDatos->TSubCat3CodSUBCAT3->Value = XDatos->QProductosSUBCAT3->Value;
                                XDatos->TSubCat3->Append();
                                XDatos->TSubCat3SUBCAT3->Value = StringGrid1->Cells[5][f];
                                XDatos->TSubCat3SUBCAT2->Value = XDatos->QProductosSUBCAT2->Value;
                                XDatos->QProductosSUBCAT3->Value = XDatos->TSubCat3CodSUBCAT3->Value;
                                XDatos->TSubCat3->Post();
                        }
                        XDatos->QProductosPRODUCTO->Value = StringGrid1->Cells[6][f];
                        XDatos->QProductosKEY->Value = StringGrid1->Cells[7][f];
                        XDatos->QProductosMARCA->Value = StringGrid1->Cells[8][f];
                        esta=false;
                        while(!XDatos->TMarcas->Eof)
                        {
                                if (XDatos->TMarcasMARCA->Value == XDatos->QProductosMARCA->Value)
                                        esta=true;
                                XDatos->TMarcas->Next();
                        }
                        if (!esta)
                        {
                                XDatos->TMarcas->Append();
                                XDatos->TMarcasMARCA->Value = XDatos->QProductosMARCA->Value;
                                XDatos->TMarcas->Post();
                        }
                        XDatos->QProductosDESCRIPCION->Value = StringGrid1->Cells[9][f];
                        XDatos->QProductosCATEGORIAX->Value = StringGrid1->Cells[10][f];
                        XDatos->QProductosCATEGORIAS->Value = StringGrid1->Cells[11][f];
                        XDatos->QProductos->Post();
                        for(int c=12;c<=StringGrid1->ColCount;c++)
                        {
                                if (StringGrid1->Cells[c][f]!="")
                                {
                                        XDatos->TCaracteristicas->Append();
                                        XDatos->TCaracteristicasLuCATEGORIA->Value = StringGrid1->Cells[2][f];
                                        XDatos->TCaracteristicasLuSUBCAT1->Value = StringGrid1->Cells[3][f];
                                        XDatos->TCaracteristicasLuSUBCAT2->Value = StringGrid1->Cells[4][f];
                                        XDatos->TCaracteristicasLuSUBCAT3->Value = StringGrid1->Cells[5][f];
                                        XDatos->TCaracteristicasref->Value = StringGrid1->Cells[0][f];
                                        if (c % 2 ==0)
                                                XDatos->TCaracteristicasCARACTERISTICA->Value = StringGrid1->Cells[c][f];
                                        else
                                                XDatos->TCaracteristicasVALOR->Value = StringGrid1->Cells[c][f];

                                        XDatos->TCaracteristicas->Post();
                                }
                        }
                }
        }

Compilar compila bien, el problema es que cuando le doy a importar, me salta el error diciéndome que el dataset no esta en edit o insert mode lo cual no entiendo, ya que antes de asignarle valores pongo el
XDatos->TCategoria->Append();.

Espero que haya quedado claro el problema, si alguien tiene alguna idea sobre que puede pasar, o a alguien le ha pasado algo parecido agradecería la ayuda.

Gracias de ante mano.

Casimiro Notevi 10-05-2012 13:01:29

Mira si te sirve algunos de los enlaces del final de esta misma página :)

ErYcK 10-05-2012 13:34:45

Gracias
 
Gracias cuando busque en el foro no encontre esos temas :)

lmpadron 23-05-2012 15:11:57

Cita:

Empezado por ErYcK (Mensaje 432279)
Compilar compila bien, el problema es que cuando le doy a importar, me salta el error diciéndome que el dataset no esta en edit o insert mode lo cual no entiendo, ya que antes de asignarle valores pongo el
Código:

XDatos->TCategoria->Append();

al principio de tu código debes poner la tabla en edición.
Código:

XDatos->TCategoria->State = dsEdit;
XDatos->TCategoria->Append()

Lo que pasa es exactamente eso, que no tienes la tabla en el modo de inserción o edición (DataSet not in Edit or Insert mode). Append crea un nuevo registro en blanco al final del DataSet listo para recibir los datos que vas a insertar en él, pero para hacerlo la tabla necesita estar en Edición o Inserción por eso el error.
Saludos


La franja horaria es GMT +2. Ahora son las 06:38:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi