请教修改一段代码(100分)

  • 主题发起人 主题发起人 xhliang
  • 开始时间 开始时间
X

xhliang

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码在重复执行时会出现: 对象打开时,不允许操作的提示,不知何解?请各位指教!
procedure TForm58.Button2Click(Sender: TObject);
var
connstr:string;
begin
if OpenDialog1.Execute then
begin
connstr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
connstr:=connstr+OpenDialog1.FileName;
connstr:=connstr+';Mode=Read;Extended Properties=Excel 8.0;Persist Security Info=False';
frmparame.ADOConnection1.ConnectionString:=connstr;
frmparame.ADOConnection1.Connected:=True;
frmparame.ADOConnection1.GetTableNames(ListBox1.Items,False);
 
procedure TForm58.Button2Click(Sender: TObject);
var
connstr:string;
begin
if OpenDialog1.Execute then
begin
connstr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
connstr:=connstr+OpenDialog1.FileName;
connstr:=connstr+';Mode=Read;Extended Properties=Excel 8.0;Persist Security Info=False';
frmparame.ADOConnection1.Close; //加上这一句
frmparame.ADOConnection1.ConnectionString:=connstr;
try
frmparame.ADOConnection1.Connected:=True;
except
ShowMessage('连接数据库失败!');
Exit;
end;
frmparame.ADOConnection1.GetTableNames(ListBox1.Items,False);
 
多谢指教!
 
后退
顶部