procedure TForm1.Button1Click(Sender: TObject);
var
 sSql:string;
begin
 
  sSql:='insert into ddd select * from OPENROWSET'+'('+'MICROSOFT.JET.OLEDB.4.0'+','+'Excel 5.0'+';'+'HDR=YES;DATABASE=d:\ss.xls'+','+'sheet1$')';
  with adoconnection1 do
  begin
   connected:=True;
   Execute(sSql);
  end;end;

解决方案 »

  1.   

    sSql:='insert into ddd select * from OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 5.0;HDR=YES;DATABASE=d:\ss.xls'',''''sheet1$'''')';在执行时.出现sheet$附近有语法错误
    不明白是什么错误.
      

  2.   

    你用的引号不对,参考:
    select * into #temp1 from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="D:\Excel2005\28.xls";User ID=Admin;Password=;Extended properties=Excel 5.0;Persist Security Info=false')...[sheet1$]
      

  3.   

    现在改为
    sSql:='insert into ddd select * from OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 8.0;HDR=YES;DATABASE=d:\ss.xls'',''sheet1$'')';
    这样可以通过.但是又出现一个错误:无效的SQL语句.期待DELTE,UPDATE,SELECT.
    是怎么回事?
      

  4.   

    首先你要确保你上面的SQL语句在查询分析器中能正确执行啊.然后再sSql:=SQL语句
      

  5.   

    参考:
    1..
    SELECT * 
    FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="C:\temp\b.xls";Extended Properties="Excel 5.0;HDR=Yes;";Persist Security Info=False')...sheet1$
    2..
    用ADO的话,可以先把excel文件读出来,读出来之后怎么倒就不用俺说了吧?呵呵
      with adqTemp do
      begin
        Close;
        ConnectionStr := 'Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Persist Security Info=false;Data Source=''c:\文件.xls''';
        CommandText := 'SELECT * from [Sheet1$]';
        Open;
      end;
      

  6.   

    建议你改为用存储过程来写,后用STOREPROC控件来调用啊.这样就不用那么麻烦了.我也是这样做的.
    select * into #temp1 from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="D:\Excel2005\28.xls";User ID=Admin;Password=;Extended properties=Excel 5.0;Persist Security Info=false')...[sheet1$]
      

  7.   

    你那是錯誤的插入記錄語句.
    理應:sSql:='select * from opendatasource('.....') insert into ddd'
      

  8.   

    sheet1$要加上[],只是知道这么用,但不知为什么,
    [sheet1$]才对
      

  9.   

    你看你的xls里sheet1是不是换成了其他的名字了?