SqlStr := 'Insert Into Sys_t_Tables (TablesID,SAPTablesCode,TablesCode,TablesName,SortNO,Re,Status) Values(7,'T002','T002','4',3,'4','1') #13#10 insert into TABLES_MODULE_RELATION values (7,7,1)';
function TdmPubData.ExecSqlNoTrans(SqlStr: WideString;cmd: TADOCommand;
const IsLocal: boolean;aShowMsg:Boolean): boolean;
var lstSql: TStringList;
i,iRowCount: integer;
OldCur:TCursor;
begin
Result := false;
OldCur:=Screen.Cursor;
Screen.Cursor:=crHourGlass;
sErrInfo:= '';
if IsConnected(IsLocal) then
begin
cmd.Connection := GetConnection(IsLocal);
lstSql := TStringList.Create;
try
lstSql.Text := SqlStr;
try
for i:=0 to lstSql.Count-1 do
begin
cmd.CommandText := lstSql[i];
if length(trim(cmd.CommandText))<2 then Continue;
cmd.Execute(iRowCount);
end;
Result := true;
except
sErrInfo := lstSql[i];
if aShowMsg then
application.MessageBox(pChar(sErrInfo),'系统提示:',mb_IconInformation);
end;
finally
lstSql.Free;
Screen.Cursor:=OldCur;
end;
end;
end;
insert yyyy;
一般都是 str1 + #13#10 + str2 这样子拼凑的。你可以写个函数,以分号作为分隔符,提取出两条insert语句然后逐条执行
但是为什么你一定要将SQL语句写死呢?char *GetToken(char *s1,char *s2)
{
char *str1,*str2;
static char str[255]; str1=strstr(s1,s2);
if (str1==NULL)
{
strcpy(str,s1);
s1[0]='\0';
}
else
{
s1[str1-s1]='\0';
strcpy(str,s1);
strcpy(s1,str1+strlen(s2));
}
return str;
}这是个C代码,可以转换成delphi,可以根据字符来分割字符串