function ff(tblanme,f1name,f2name,... : String) : Boolean; begin //添加 Close; SQL.Clear; SQL.Add('Insert into table'+tblname+'('''+f1name+''','''+f2name+...+'''') values(''ss'',''dd'',....)'); ExcSQL; 但是这只是 A表中的字段,如果换成B表的字段该怎么办呢? 总不能再写一条Insert吧! 那我这个函数还有 什么用呢? update也是这个道理,是这个意思吗? end;
假设你使用了一个ADOCommand 那就是 function ff(ArrayA:Array of string) var MyADOCommand:TADOCommand; I,J:Integer; tabName,strSQL:String; begin I:=length(ArrayA); case I of 2:tabName:='a'; 3:tabName:='b'; 4:tabName:='c'; end; strSQL:='insert into '+tabName; for J:=0 to I-1 do begin end;
end;
假设你使用了一个ADOCommand 那就是 function ff(ArrayA:Array of string) var MyADOCommand:TADOCommand; I,J:Integer; tabName,strSQL:String; begin I:=length(ArrayA); case I of 2:tabName:='a'; 3:tabName:='b'; 4:tabName:='c'; end; strSQL:='insert into '+tabName; for J:=0 to I-1 do begin ...........(这个不用写了吧,呵呵) end; .... try MyADOCommand.Excute; Except
end; MyADOCommand.free;
end;
//参数: //TableName : 字符串, 要操作的表的名字 //TableRecord: 字符串数组, 存储表中各个字段的字段名 //RecordValue: 字符串数组, 存储各个字段对应的真实的要插入的值 //ArrayBund : 整型, 上面两个数组的元素个数 //功能: //根据传入的两个数组,构造出一个插入的SQL语句,并且执行这条语句,将数据插入表 function Insert( TableName : string , TableRecord: Array of string , RecordValue: Array of string , ArrayBound: Integer) var strSQL: String ; i : Integer; begin strSQL = "" strSQL = strSQL + "INSERT INTO" + " " + TableName + " "; for i:=0 to ArrayBound do begin strSQL = strSQL + "('" + TableRecord(i) + "')"; end; strSQL = strSQL + " " + "VALUES" ; for i:=0 to ArrayBound do begin strSQL = strSQL + "('" + RecordValue(i) + "')"; end; //这样,strSQL就是插入的SQL语句, 在下面执行 strSQL语句就能插入表中了. .... end;
这个Insert插入呢?c表也是这样一直到n表的
begin
//添加
Close;
SQL.Clear;
SQL.Add('Insert into table'+tblname+'('''+f1name+''','''+f2name+...+'''') values(''ss'',''dd'',....)');
ExcSQL;
但是这只是 A表中的字段,如果换成B表的字段该怎么办呢? 总不能再写一条Insert吧! 那我这个函数还有
什么用呢? update也是这个道理,是这个意思吗?
end;
那就是
function ff(ArrayA:Array of string)
var
MyADOCommand:TADOCommand;
I,J:Integer;
tabName,strSQL:String;
begin
I:=length(ArrayA);
case I of
2:tabName:='a';
3:tabName:='b';
4:tabName:='c';
end;
strSQL:='insert into '+tabName;
for J:=0 to I-1 do
begin end;
end;
那就是
function ff(ArrayA:Array of string)
var
MyADOCommand:TADOCommand;
I,J:Integer;
tabName,strSQL:String;
begin
I:=length(ArrayA);
case I of
2:tabName:='a';
3:tabName:='b';
4:tabName:='c';
end;
strSQL:='insert into '+tabName;
for J:=0 to I-1 do
begin
...........(这个不用写了吧,呵呵)
end;
....
try
MyADOCommand.Excute;
Except
end;
MyADOCommand.free;
end;
//TableName : 字符串, 要操作的表的名字
//TableRecord: 字符串数组, 存储表中各个字段的字段名
//RecordValue: 字符串数组, 存储各个字段对应的真实的要插入的值
//ArrayBund : 整型, 上面两个数组的元素个数
//功能:
//根据传入的两个数组,构造出一个插入的SQL语句,并且执行这条语句,将数据插入表
function Insert( TableName : string , TableRecord: Array of string ,
RecordValue: Array of string , ArrayBound: Integer)
var
strSQL: String ;
i : Integer;
begin
strSQL = ""
strSQL = strSQL + "INSERT INTO" + " " + TableName + " ";
for i:=0 to ArrayBound do
begin
strSQL = strSQL + "('" + TableRecord(i) + "')";
end;
strSQL = strSQL + " " + "VALUES" ;
for i:=0 to ArrayBound do
begin
strSQL = strSQL + "('" + RecordValue(i) + "')";
end;
//这样,strSQL就是插入的SQL语句, 在下面执行 strSQL语句就能插入表中了.
....
end;