2012-06-27 2 views
0

:ADO를 사용하여 Excel 파일에 값을 삽입하는 방법은 무엇입니까? 내가 Excel 파일에 값을 삽입하려면 다음 코드를 사용하고

sAppend:='INSERT INTO ["Excel 8.0;Database=' + Edit1.Text + ';"].[Sheet1$] (d) ' + FormatDateTime('d/m/yyyy', now)+';'; 
AdoQuery1.SQL.Text:=sAppend; 
AdoQuery1.ExecSQL; 

이전 루틴이 완전히 표시됩니다. 엑셀에

연결 파일

procedure TForm1.ConnectToExcel; 
var strConn : widestring; 
begin 
    strConn:='Provider=Microsoft.Jet.OLEDB.4.0;' + 
    'Data Source=' + Edit1.Text + ';' + 
    'Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";Persist Security Info=False'; 

    AdoConnection1.Connected:=False; 
    AdoConnection1.ConnectionString:=strConn; 
    try 
    AdoConnection1.Open; 
    AdoConnection1.GetTableNames(ComboBox1.Items,True); 
    except 
    ShowMessage('Unable to connect to Excel, make sure the workbook ' + Edit1.Text +  'exist!'); 
    raise; 
    end; 
end;(*ConnectToExcel*) 

procedure TForm1.FetchData; 
begin 
    StatusBar1.SimpleText:=''; 

    if not AdoConnection1.Connected then ConnectToExcel; 

    AdoQuery1.Close; 
    AdoQuery1.SQL.Text:=Edit2.Text; 
    try 
    AdoQuery1.Open; 
    except 
    ShowMessage('Unable to read data from Excel, make sure the query ' + Edit1.Text + ' is meaningful!'); 
    raise; 
    end; 
end; 

사람이 내가 잘못 뭐하는 거지 말씀해 주시겠습니까?

오류는 "INSERT INTO 문에서 구문 오류"입니다.

+3

사용중인 연결 문자열 받고있는 오류를 포함하여, 전체 소스 코드를 게시하시기 바랍니다. – RRUZ

답변

1

찾을 솔루션 :

sAppend:='INSERT INTO [Sheet1$] (d) values ("' + DateToStr(now) +'")'; 
AdoQuery1.SQL.Text:=sAppend; 
AdoQuery1.ExecSQL; 
+1

다른 지역을 사용하는 사용자와 함께 작동하도록기도하십시오. –

관련 문제