![]() |
Erro extraño al insertar registro
hola amigos miren aquie con un problema...cuando inserto un nui¿evo registro me mando error que segun hay un error con la llave primaria (duplicado) aunque no es verdad. aunque al final lo siempre si guarda el registro aqui dejo el codigo:::
procedure TFrmEmpleados.BtnGuardarClick(Sender: TObject); var global : integer; begin global :=0; if CmbDireccion.Text='' then begin global:=1; CmbDireccion.color:=clInactiveCaptionText; end; //........................................................ if EdNumEmpleado.Text='' then begin global:=1; EdNumEmpleado.color:=clInactiveCaptionText; end; //............................. if Ednombre.Text='' then begin global:=1; Ednombre.color:=clInactiveCaptionText; end; //............................ if EdAppaterno.Text='' then begin global:=1; EdAppaterno.color:=clInactiveCaptionText; end; //............................ if EdApmaterno.Text='' then begin global:=1; EdApmaterno.color:=clInactiveCaptionText; end; //............................ if EdNivel.Text='' then begin global:=1; EdNivel.color:=clInactiveCaptionText; end; //............................ if EdLogin.Text='' then begin global:=1; EdLogin.color:=clInactiveCaptionText; end; //............................ if EdPassword.Text='' then begin global:=1; EdPassword.color:=clInactiveCaptionText; end; if global = 1 then begin Showmessage('Rellene los campos marcados para continuar'); global:=0; end else if global = 0 then begin {Verificar si ya existe el producto} Datos.QryEmpleado.Active:= False; Datos.QryEmpleado.SQL.Clear; Datos.QryEmpleado.SQL.Add('SELECT *'); Datos.QryEmpleado.SQL.Add('FROM Empleado'); Datos.QryEmpleado.SQL.Add('WHERE NumeroEmpleado =' + '''' + EdNumEmpleado.Text + ''''); Datos.QryEmpleado.Active:= True; If Datos.QryEmpleado.RecordCount > 0 then Application.MessageBox('La clave de empleado ya existe. Verifique los datos !!!', 'Error', MB_OK + MB_ICONERROR) Else LblEncriptado.Caption := encriptar(EdPassword.Text, 10); Datos.QryEmpleado.Active:= False; Datos.QryEmpleado.SQL.Clear; Datos.QryEmpleado.SQL.Add('INSERT INTO Empleado VALUES('); Datos.QryEmpleado.SQL.Add(Quotedstr(EdNumEmpleado.Text) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(LblClaveDireccion.Caption) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(EdLogin.Text) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(LblEncriptado.caption) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(EdNombre.Text) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(EdAppaterno.Text) + ','); Datos.QryEmpleado.SQL.Add(Quotedstr(EdApmaterno.Text) + ','); Datos.QryEmpleado.SQL.Add(EdNivel.Text + ')'); Datos.QryEmpleado.ExecSQL; Datos.QryEmpleado.Active:= True; //limpiar de componentes lblEncriptado.Caption:=''; EdNumEmpleado.Text:=''; LblClaveDireccion.Caption:=''; Edlogin.Text:=''; EdNombre.Text:=''; EdAppaterno.Text:=''; EdApmaterno.Text:=''; EdNivel.Text:=''; //BtnNuevo.Enabled:=true; end; end; |
Hola,
Sobra la línea que dice Datos.QryEmpleado.Active:= True; Ya que con ExecSql ya se está ejecutando una vez el Insert. |
resuelto
bueno de nueva cuenta gracias...problema solucionado......
gracias TOPX |
| La franja horaria es GMT +2. Ahora son las 15:11:12. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi