1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
Function BDD_Ajouter_Champ(NomRep,NomTbl,NomChp,TypChp:String;Var Err_Ch:String):Boolean;
Var Qry:TQuery;
Begin
Result := False;
Err_Ch := '';
Qry := TQuery.Create(Nil);
Try
Qry.DataBaseName := NomRep;
Qry.Sql.Text := 'Alter Table '+QuotedStr(NomTbl);
Qry.Sql.Add('ADD '+NomChp+' '+TypChp);
Try
Qry.ExecSql;
Result := True;
Except
Err_Ch := 'Exception = '+Exception(ExceptObject).Message;
End;
Finally
Qry.Free;
End;
//Pour appeler la fonction tu peux faire un truc du genre
procedure TForm1.BtAjtChpClick(Sender: TObject);
Var Err_Ch:String;
begin
Table1.Close;
If Not BDD_Ajouter_Champ(Table1.DataBaseName,Table1.TableName,'Chp_Ch','Char(20)',Err_Ch)
Then Begin
ShowMessage(Err_Ch);
Exit;
End;
ShowMessage('Ok 1');
If Not BDD_Ajouter_Champ(Table1.DataBaseName,Table1.TableName,'Chp_Int','Integer',Err_Ch)
Then Begin
ShowMessage(Err_Ch);
Exit;
End;
ShowMessage('Ok 2');
end; |
Partager