Ver Mensaje Individual
  #36  
Antiguo 06-01-2008
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Reputación: 25
Caral Va por buen camino
Hola
El problema esta muy facil de solucionar, el campo no se llama como lo tienes, revisalo.
Código Delphi [-]
Var
 agregar:String;
 Co:Integer;
begin
 //Primero Buscar el Registro para ver si está .  Y verifica tambien el codigo
  FormGrupos.ADOQuery1.Active := False;
  FormGrupos.ADOQuery1.SQL.Text := 'Select Nombre From TGrupos WHERE Nombre = :Nombre';
  FormGrupos.ADOQuery1.Parameters.Parambyname('Nombre').Value:= Edit1.Text;
  FormGrupos.ADOQuery1.Active := True;
  If Edit1.Text = FormGrupos.ADOQuery1.Fields[0].Value then   begin
     MessageDlg('El Grupo :  '+Edit1.Text+' ya Existe ',mtError,[mbOK],0);
     Edit1.text:='';
     Edit1.SetFocus;
     end
  else begin
    //Ahora me fijo el Código si ya existe.
        FormGrupos.ADOQuery1.SQL.Clear;
        FormGrupos.ADOQuery1.Active := False;
        FormGrupos.ADOQuery1.SQL.Text:= 'Select Codigo_G  From TGrupos Where Codigo_G = :Cod';
        FormGrupos.ADOQuery1.Parameters.Parambyname('Cod').Value:= Edit2.Text;
        FormGrupos.ADOQuery1.Active:=true;
        If Edit2.Text = FormGrupos.ADOQuery1.Fields[0].Value Then begin
           MessageDlg('El Código: '+Edit2.Text+', ya existe', mtError,[mbOk],0);
           Edit2.Text:='';
           Edit2.SetFocus;
         end

         else   //Esta todo bien entonces agrego.
                begin
                        FormGrupos.ADOQuery1.Active := False;
                        FormGrupos.ADOQuery1.SQL.Text:= 'Insert Into TGrupos (Nombre, Codigo_G) Values (:Nombre, :Codigo)';
                        FormGrupos.ADOQuery1.Parameters.Parambyname('Nombre').Value:= Edit1.Text;
                        FormGrupos.ADOQuery1.Parameters.Parambyname('Codigo').Value:= StrToInt(Edit2.Text);
                        FormGrupos.ADOQuery1.ExecSQL;
                        Showmessage('El Grupo se inserto bien');

          end;
       end;
En algun momento le cambiaste el nombre.
Estoy viendo el programita, quieres algo mas?
Saludos
Responder Con Cita