vSQL :=' Select cast(客户编号 as dec(28)),厨旧表号,主卫旧表号,共卫旧表号,阳旧表号1,物理地址1, 物理地址2, 物理地址3, 物理地址4 From OpenRowSet'
+'(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=d:\a.xls'',['+vSheet+']) where 客户编号<>'''')';提示---------------------------
Debugger Exception Notification
---------------------------
Project Parse.exe raised exception class EOleException with message '')' 附近有语法错误。'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
+'(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=d:\a.xls'',['+vSheet+']) where 客户编号<>'''')';提示---------------------------
Debugger Exception Notification
---------------------------
Project Parse.exe raised exception class EOleException with message '')' 附近有语法错误。'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
procedure TForm1.Button1Click(Sender: TObject);//在数据库中自动生成表qqq
var s:string;
ADOConn:TADOConnection;
aDataSet:TADODataSet;
begin
if OpenDialog1.Execute then
begin
ADOConn:=TADOConnection.Create(self);
ADOConn.LoginPrompt:=false;
ADOConn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+OpenDialog1.FileName
+';Extended Properties=Excel 8.0;Persist Security Info=False';
aDataSet:=TADODataSet.Create(self);
aDataSet.Connection:=ADOConn;
ADOConn.OpenSchema(siTables,EmptyParam,EmptyParam,aDataSet);
aDataSet.Last;
s:=aDataSet.Fields.Fields[2].AsString;//获取第一工作表表名
aDataSet.Close;
aDataSet.Free;
ADOConn.Close;
ADOConn.Free;
ADOQuery2.Connection:=ADOConnection1;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('select * into qqq from OPENROWSET(');//将这个‘qqq’字改为你的数据库中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 5.0;HDR=YES;Excel 8.0;DATABASE='+OpenDialog1.FileName)+',['+s+'])');
ADOQuery2.ExecSQL;
showmessage('ok');
end;
end;
procedure TForm1.Button3Click(Sender: TObject);//在数据库中已经存在表qqq
var s:string;
ADOConn:TADOConnection;
aDataSet:TADODataSet;
begin
if OpenDialog1.Execute then
begin
ADOConn:=TADOConnection.Create(self);
ADOConn.LoginPrompt:=false;
ADOConn.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+OpenDialog1.FileName
+';Extended Properties=Excel 8.0;Persist Security Info=False';
aDataSet:=TADODataSet.Create(self);
aDataSet.Connection:=ADOConn;
ADOConn.OpenSchema(siTables,EmptyParam,EmptyParam,aDataSet);
aDataSet.Last;
s:=aDataSet.Fields.Fields[2].AsString;//获取第一工作表表名
aDataSet.Close;
aDataSet.Free;
ADOConn.Close;
ADOConn.Free;
ADOQuery2.Connection:=ADOConnection1;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Append('insert into qqq select * from OPENROWSET(');//将这个‘qqq’字改为你的数据库中的表名
ADOQuery2.SQL.Append(quotedstr('MICROSOFT.JET.OLEDB.4.0'));
ADOQuery2.SQL.Append(','+quotedstr('Excel 5.0;HDR=YES;Excel 8.0;DATABASE='+OpenDialog1.FileName)+',['+s+'])');
ADOQuery2.ExecSQL;
showmessage('ok');
end;
end;