G
gxw
Unregistered / Unconfirmed
GUEST, unregistred user!
function AdoExec(SqlText: string): boolean;
begin
with Form1.ADOQuery1 do
try
Close; Connection:=Form1.ADOConnection1; Sql.clear; Sql.add(sqlText); ExecSql;
Result:=True;
except
on e:exception do
begin
Result:=False;
ShowMessage(e.Message);
end;
end
end;
function CreateTable(TableName: string; StruID: integer): Boolean;
begin
case StruID of
0: Result:=AdoExec('Create Table '+TableName+'(Code VarChar(12) PRIMARY KEY,Name VarChar(40),Unit VarChar(8),kind VarChar(20))');
1: Result:=AdoExec('Create Table '+TableName+'(Id Int IDENTITY(1,1) PRIMARY KEY,Code VarChar(12),Billno VarChar(12))');
2: ....
3: ....
else
Result:=False;
end;
end;
function CreateTempTable(TableStruId: integer): string;
begin
Randomize;
Result:='#Temp'+inttostr(random(100000));
CreateTable(Result,TableStruId);
end;
//------------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);//-----Form1测试
var
TableName: string;
begin
TableName:=CreateTempTable(1);
ShowMessage(TableName);
//--------------检查tempdb内已创建了临时表TableName
end;
procedure TForm2.Button1Click(Sender: TObject);//-----Form2测试
var
TableName: string;
begin
TableName:=CreateTempTable(1);
ShowMessage(TableName);
//------------没报错,但查询分析器看并没有临时表被创建,其余窗口测试情况均相同。为何Form1就可以?
end;
begin
with Form1.ADOQuery1 do
try
Close; Connection:=Form1.ADOConnection1; Sql.clear; Sql.add(sqlText); ExecSql;
Result:=True;
except
on e:exception do
begin
Result:=False;
ShowMessage(e.Message);
end;
end
end;
function CreateTable(TableName: string; StruID: integer): Boolean;
begin
case StruID of
0: Result:=AdoExec('Create Table '+TableName+'(Code VarChar(12) PRIMARY KEY,Name VarChar(40),Unit VarChar(8),kind VarChar(20))');
1: Result:=AdoExec('Create Table '+TableName+'(Id Int IDENTITY(1,1) PRIMARY KEY,Code VarChar(12),Billno VarChar(12))');
2: ....
3: ....
else
Result:=False;
end;
end;
function CreateTempTable(TableStruId: integer): string;
begin
Randomize;
Result:='#Temp'+inttostr(random(100000));
CreateTable(Result,TableStruId);
end;
//------------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);//-----Form1测试
var
TableName: string;
begin
TableName:=CreateTempTable(1);
ShowMessage(TableName);
//--------------检查tempdb内已创建了临时表TableName
end;
procedure TForm2.Button1Click(Sender: TObject);//-----Form2测试
var
TableName: string;
begin
TableName:=CreateTempTable(1);
ShowMessage(TableName);
//------------没报错,但查询分析器看并没有临时表被创建,其余窗口测试情况均相同。为何Form1就可以?
end;