由原文http://www.codefans.net/soft/20922.shtml得到delphi insert的使用方法
感觉很好用
其代码为:
unit Unit2;
//Download by http://www.codefans.net
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Panel1: TPanel;
Label1: TLabel;
Label3: TLabel;
Label5: TLabel;
Edit5: TEdit;
Edit3: TEdit;
Edit1: TEdit;
Label2: TLabel;
Label4: TLabel;
Label6: TLabel;
Edit6: TEdit;
Edit4: TEdit;
Edit2: TEdit;
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
Form1.ADOQuery1.close;
Form1.ADOQuery1.SQL.Clear;
Form1.ADOQuery1.SQL.Add('Insert into 商品基础信息表(商品名称,商品代码,规格,单位,单价,商品说明)');
Form1.ADOQuery1.SQL.Add('Values(:A,:B,:C,:D,:E,:F)');
Form1.ADOQuery1.Parameters.ParamByName('A').Value:=Edit1.Text;
Form1.ADOQuery1.Parameters.ParamByName('B').Value:=Edit2.Text;
Form1.ADOQuery1.Parameters.ParamByName('C').Value:=Edit3.Text;
Form1.ADOQuery1.Parameters.ParamByName('D').Value:=Edit4.Text;
Form1.ADOQuery1.Parameters.ParamByName('E').Value:=StrToInt(Edit5.Text);
Form1.ADOQuery1.Parameters.ParamByName('F').Value:=Edit6.Text;
Form1.ADOQuery1.ExecSQL;
Form1.ADOTable1.Close;
Form1.ADOTable1.Open;
end;
end.
工程文件下载地址:http://download.csdn.net/detail/u013183444/6774707
================================================================================================================
================================================================================================================
将其改进到Interbase使用:IB的控件为:
数据库表中字段类型为:
界面为:
使用的代码为:
procedure TForm6.addButtonClick(Sender: TObject);
var
maxIndex : integer;
tempStr : string;
begin
form1.IBdatabase1.Connected:=true;
form1.IBquery1.Close;
form1.ibquery1.SQL.Clear;
form1.ibquery1.SQL.Add('select max(loadIndex) from loadmatrix');
form1.ibquery1.Open; //这时值已经放到IBQuery中了
maxIndex := form1.IBQuery1.FieldByName('max').AsInteger ;
form1.ibquery1.SQL.Clear;
tempStr := inttoStr(maxIndex+1);
Form1.IBQuery1.sql.Add('Insert into loadmatrix(loadIndex,loadname,phase,har1,har3,har5,har7,har9)');
Form1.IBQuery1.sql.Add('Values(:A,:B,:C,:D,:E,:F,:G,:H)');
Form1.IBQuery1.Params.ParamByName('A').Value:=(maxIndex+1) ;//integer型数据
Form1.IBQuery1.Params.ParamByName('B').Value:=editname.Text ;//char型数据
Form1.IBQuery1.Params.ParamByName('C').Value:=strtofloat(editphase.Text) ;//float型数据
Form1.IBQuery1.Params.ParamByName('D').Value:=strtofloat(editHar1.Text) ;
Form1.IBQuery1.Params.ParamByName('E').Value:=strtofloat(editHar3.Text) ;
Form1.IBQuery1.Params.ParamByName('F').Value:=strtofloat(editHar5.Text );
Form1.IBQuery1.Params.ParamByName('G').Value:=strtofloat(editHar7.Text) ;
Form1.IBQuery1.Params.ParamByName('H').Value:=strtofloat(editHar9.Text );
form1.ibquery1.ExecSQL;
form1.IBquery1.Close;
form1.ibquery1.SQL.Clear;
form1.ibquery1.SQL.Add('select * from loadmatrix');
form1.ibquery1.Open;
end;