PDA

Ver la Versión Completa : ayuda error eof in string detected


Rofocale
06-10-2010, 21:13:06
Hola a todos este codigo uso para insertar datos en una tabla y me da error de eof in string detected que es lo que esta mal..
alguien me ayuda ?

gracias
if(iCliente < 1) then
sCliente := 'null'
else
sCliente := IntToStr(iCliente);
with dmDatos.qryAuxiliar1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO ventasareas (orden, articulo, codigo, descrip, cantidad, precio, tipo,categoria, fecha) VALUES(');
SQL.Add(IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' + grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' + grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' + grdDatos.Cells[6,iRenglon] + ',');
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add('null,');
SQL.Add('''' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ')');
ExecSQL;
Close;
end;

Caral
06-10-2010, 21:22:46
Hola
No entiendo muy bien que pretendes con tanto add, pero si hace falta varios + si se añade un dato.

SQL.Add('INSERT INTO ventasareas '+
' (orden, articulo, codigo, descrip, cantidad, precio, tipo,categoria, fecha)'+
' VALUES('+IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] ')');

if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(','+ grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add(','null,');
SQL.Add('''' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ')');
ExecSQL;
Close;
Saludos

Rofocale
06-10-2010, 21:55:05
no funciona
grdDatos.Cells[6,iRenglon] ')'); <--- esta parte ahi no termina

QuotedStr(grdDatos.Cells[15,iRenglon]) + ')'); <--- aqui recien se cierra el parentisis

SQL.Add(','null,'); <-- aqui tambien esta mal

bueno de todas maneras me sigue saliendo eof in string detected

:(

Caral
06-10-2010, 22:04:25
Hola
Tienes 9 campos a actualizar con la inserción.
(orden, articulo, codigo, descrip, cantidad, precio, tipo, categoria, fecha)
Tienes 7 campos en la sentencia insert.
Tiene la opcion de añadir 1 campo mas si cumple con el IF, de lo contrario acualiza los 9 campos.
Que quieres que entienda el programa????:::::
Un hermoso eof detected.
La unica manera que se me ocurre es usar tres sql en la misma linea.
Saludos

Caral
06-10-2010, 22:23:21
Hola
Explicandolo con codigo:

// inserto 7 campos
SQL.Text:= 'INSERT INTO ventasareas '+
' (orden, articulo, codigo, descrip, cantidad, precio, tipo)'+
' VALUES('+IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] +')';

// Creo una condicion
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
begin
// si se cumple inserto 8 campos
SQL.Text:= 'INSERT INTO ventasareas '+
' (orden, articulo, codigo, descrip, cantidad, precio, tipo, categoria)'+
' VALUES('+IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] + ',' + grdDatos.Cells[10,iRenglon] +')';
end
else
begin
// si no se cumple inserto 9 campos
SQL.Text:= 'INSERT INTO ventasareas '+
' (orden, articulo, codigo, descrip, cantidad, precio, tipo, categoria, fecha)'+
' VALUES('+IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] + ',' + grdDatos.Cells[10,iRenglon] + ',' +
QuotedStr(grdDatos.Cells[15,iRenglon]) +')';
end;
ExecSQL;
Close;
OJO hago ver que el dato fecha no coincidiría, pero asi es como lo tienes.
para mi se tendria que generar una condicion al inicio, de lo contrario hara el insert dos veces en este ejemplo.
Saludos

Rofocale
07-10-2010, 00:12:58
este codigo funcionaba bien pero yo le quite uno que otro campo y lo deje como te lo enseñe pero bueno no se porque da error, aqui si funciona bien..
with dmDatos.qryAuxiliar1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO ventasareas (areaventa, orden, articulo, codigo, descrip, cantidad, precio, iva, tipo,');
SQL.Add('descauto, descotorg, descfechas, descusuario, cliente, comprobante, categoria, departamento,');
SQL.Add('comentario, fecha, vendedor, cantidad_cnt) VALUES(');
SQL.Add(sAreaVenta + ',' + IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',');
SQL.Add('''' + grdDatos.Cells[1,iRenglon] + ''',''' + grdDatos.Cells[2,iRenglon] + ''',');
SQL.Add(grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',');
SQL.Add(grdDatos.Cells[5,iRenglon] + ',' + grdDatos.Cells[6,iRenglon] + ',');
SQL.Add('''' + grdDatos.Cells[7,iRenglon] + ''',' + grdDatos.Cells[8,iRenglon] + ',' + grdDatos.Cells[13,iRenglon] + ',');
SQL.Add(grdDatos.Cells[9,iRenglon] + ',' + sCliente + ',''' + Copy(txtComprobante.Text,1,1) + ''',');
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add('null,');
if(Length(grdDatos.Cells[11,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[11,iRenglon] + ',')
else
SQL.Add('null,');
SQL.Add('''' + grdDatos.Cells[14,iRenglon] + ''',' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ',');
SQL.Add(sVendedor + ',''' + grdDatos.Cells[16,iRenglon] + ''')');
ExecSQL;
Close;

Rofocale
07-10-2010, 16:17:39
alguna idea ? 8-)

ElKurgan
08-10-2010, 07:35:56
Código Delphi [-] (http://www.clubdelphi.com/foros/newreply.php?do=newreply&p=378621#)

SQL.Clear;
SQL.Add('INSERT INTO ventasareas (orden, articulo, codigo, descrip, cantidad, precio, tipo,categoria, fecha) VALUES(');
SQL.Add(IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] + ','); // <----- ¿¿??
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
....


A lo mejor me equivoco, pero si el código que tienes es el que muestras, no puedes terminar una sentencia insert como está escrita, con una coma.

Prueba con esto, a ver si va:


SQL.Add(IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' +
grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' +
grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] );


Un saludo

Rofocale
09-10-2010, 16:54:37
no funciona :(

Rofocale
13-10-2010, 20:12:32
Hola nadie puede hecharme una mano ?
porque este codigo si funciona


with dmDatos.qryAuxiliar1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO ventasareas (areaventa, orden, articulo, codigo, descrip, cantidad, precio, iva, tipo,');
SQL.Add('descauto, descotorg, descfechas, descusuario, cliente, comprobante, categoria, departamento,');
SQL.Add('comentario, fecha, vendedor, cantidad_cnt) VALUES(');
SQL.Add(sAreaVenta + ',' + IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',');
SQL.Add('''' + grdDatos.Cells[1,iRenglon] + ''',''' + grdDatos.Cells[2,iRenglon] + ''',');
SQL.Add(grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',');
SQL.Add(grdDatos.Cells[5,iRenglon] + ',' + grdDatos.Cells[6,iRenglon] + ',');
SQL.Add('''' + grdDatos.Cells[7,iRenglon] + ''',' + grdDatos.Cells[8,iRenglon] + ',' + grdDatos.Cells[13,iRenglon] + ',');
SQL.Add(grdDatos.Cells[9,iRenglon] + ',' + sCliente + ',''' + Copy(txtComprobante.Text,1,1) + ''',');
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add('null,');
if(Length(grdDatos.Cells[11,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[11,iRenglon] + ',')
else
SQL.Add('null,');
SQL.Add('''' + grdDatos.Cells[14,iRenglon] + ''',' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ',');
SQL.Add(sVendedor + ',''' + grdDatos.Cells[16,iRenglon] + ''')');
ExecSQL;
Close;



y este no


with dmDatos.qryAuxiliar1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO ventasareas (orden, articulo, codigo, descrip, cantidad, precio, tipo,categoria, fecha) VALUES(');
SQL.Add(IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',' + grdDatos.Cells[1,iRenglon] + ',' + grdDatos.Cells[2,iRenglon] + ',' + grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' + grdDatos.Cells[6,iRenglon] + ',');
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add('null,');
SQL.Add('''' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ')');
ExecSQL;
Close;
end;


algun error con las comas o algo ?
espero ayuda
gracias

Caral
13-10-2010, 20:45:22
Hola
Lo unico que se ve, comparandolo con el primero:

with dmDatos.qryAuxiliar1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO ventasareas (orden, articulo, codigo, descrip, cantidad, precio, tipo, categoria, fecha) VALUES(');
SQL.Add(IntToStr(iRenglon) + ',' + grdDatos.Cells[0,iRenglon] + ',''' + grdDatos.Cells[1,iRenglon] + ''',''' +
grdDatos.Cells[2,iRenglon] + ''',' + grdDatos.Cells[3,iRenglon] + ',' + grdDatos.Cells[4,iRenglon] + ',' +
grdDatos.Cells[6,iRenglon] + ',');
if(Length(grdDatos.Cells[10,iRenglon]) > 0) then
SQL.Add(grdDatos.Cells[10,iRenglon] + ',')
else
SQL.Add('null,');
SQL.Add('' + QuotedStr(grdDatos.Cells[15,iRenglon]) + ')');
ExecSQL;
Close;
end;
Saludos

Rofocale
15-10-2010, 03:12:58
porfavor me puedes explicar como van eso de las comillas unas que van asi '''' y otras asi ''',' y realmente solo he visto ',' estas y no se porque van las otras..
ojala puedas ayudarme

gracias

Rofocale
15-10-2010, 03:49:08
por otro lado el codigo me da error token unknown line 2 clolumn 1
,'.
a que se debe ?

ecfisa
15-10-2010, 04:30:45
porfavor me puedes explicar como van eso de las comillas unas que van asi '''' y otras asi ''',' y realmente solo he visto ',' estas y no se porque van las otras..
ojala puedas ayudarme gracias

Hola Rofocale.

Se usan las comillas dobles cuando se quiere que uno o más caracteres queden entre comillas
dentro de una cadena. Por ejemplo si quisieramos que en la frase: habia una vez, la palabra una
quedase entre comillas, no podemos hacer: 'habia 'una' vez', Delphi interpretaría: [un string]
[un identificador,variable, etc] [un string].

Para indicarle a Delphi que la palabra una va entre comillas, tenemos que hacer: 'había ''una'' vez',
lo que nos dá: habia 'una' vez.

Particularmente para introducir caracteres entre comillas, uso la función QuotedStr, me resulta más
legible y tiene el mismo resultado.

Un ejemplo con los dos usos:

Cadena:= 'había ''una'' vez';
Cadena:= 'había '+QuotedStr('una')+' vez'


Saludos. :)

Rofocale
15-10-2010, 15:31:51
gracias..

ahora alguien me podria ayudar el porque me sale toke unknown ,'.

gracias