Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MS SQL Server
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 04-12-2008
tebre tebre is offline
Miembro
 
Registrado: nov 2008
Posts: 93
Poder: 16
tebre Va por buen camino
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;
Responder Con Cita
  #2  
Antiguo 04-12-2008
Avatar de TOPX
TOPX TOPX is offline
Miembro
 
Registrado: may 2008
Ubicación: Bogotá
Posts: 527
Poder: 17
TOPX Va camino a la fama
Hola,

Sobra la línea que dice Datos.QryEmpleado.Active:= True;

Ya que con ExecSql ya se está ejecutando una vez el Insert.
__________________
"constructive mind, destructive thoughts"
Responder Con Cita
  #3  
Antiguo 04-12-2008
tebre tebre is offline
Miembro
 
Registrado: nov 2008
Posts: 93
Poder: 16
tebre Va por buen camino
resuelto

bueno de nueva cuenta gracias...problema solucionado......

gracias TOPX
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
cómo Insertar un registro maximo_nashir PHP 1 14-07-2007 08:06:05
Insertar un registro psll Conexión con bases de datos 2 26-10-2006 19:33:42
Problemas al insertar registro dvlt Firebird e Interbase 4 10-10-2005 20:51:59
Insertar Nuevo Registro perillan Conexión con bases de datos 3 24-04-2005 14:30:23
Error al insertar un registro en la BD RiverPlate Conexión con bases de datos 3 08-12-2004 15:53:18


La franja horaria es GMT +2. Ahora son las 00:27:07.


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
Copyright 1996-2007 Club Delphi