各位大哥,幫幫忙吧,俺現在是沒有一分的窮光蛋,分以後一定補上.
你們行行好,幫俺看以下這段代碼.其他都沒有問題,就是在將stringgrid的值賦給數據庫表單joy的時候,說'violation of primary KEY constraint'PK_JOY',can't insert duplicate key in object 'JOY'',能告訴是深麼原因嗎
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
    s:string;
begin
opendialog1.InitialDir:=ExtractFileDir(paramstr(0));
opendialog1.Execute;
Try
ExcelApplication1.Connect;
Except
MessageDlg('Excel may not be installed',mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
try
excelapplication1.Workbooks.Open(opendialog1.FileName,
null,null,null,null,null,null,null,null,null,null,null,null,0);except
begin
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;showmessage('???EXCEL?!');
exit;
end;
end;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
 for i:=1 to advstringgrid1.rowCount-1 do
  begin
 adoQuery1.Close;
 adoQuery1.sql.Clear;
 S := 'insert into joy values(''' + advstringgrid1.Cells[1,i] + ''',''' + advstringgrid1.Cells[2,i] + ''',''' + advstringgrid1.Cells[3,i] + ''')';
 adoQuery1.SQL.Add(S);
 adoQuery1.ExecSQL;end; end;end.