怎么样Delphi中ADOTable控件来执行access数据库
用SQL语句来执行
想要详细点的

解决方案 »

  1.   

    这个跟sql差不多的
    比如连接:procedure TMain_Frm.FormCreate(Sender: TObject);
    begin
      try
      execcodesoft;
      ADOConnection1.ConnectionString:=
      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+extractfilepath(Application.ExeName)+'Insdata.mdb;Persist Security Info=False';
      ADOConnection1.LoginPrompt:=False;
      ADOConnection1.Connected:=True;
      label3.Caption:=FormatDateTime('ddd',Now);
      except
        ShowMessage('你的電腦未安裝CodeSoft軟體,請進入\\172.20.1.108程式網站-->安裝CodeSoft軟體再重新運行此程式!');
        Application.Terminate;
        Application.MessageBox('數據庫連接文件出錯!請與MIS聯系!!!', '錯誤',
          MB_OK + MB_ICONSTOP);
        Application.Terminate;
        end;
    end;
      

  2.   

    再比如插入数据:procedure TMain_Frm.RzEdit7KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in ['1'..'9',#8,#13]) then key:=#0;
      if Key=#13 then
      begin
        if Length(Trim(RzEdit7.Text))<>16 then
      begin
        RzEdit7.SetFocus;
        RzEdit7.SelectAll;
        RzEdit7.Clear;
        exit;
        end
        else
        begin
          if not Insdata(ADOConnection1,RzEdit1.Text,RzEdit2.Text,RzEdit7.Text,CheckBox2) then
          begin
            label1.Caption:='NG';
            label1.Font.Color:=clRed;
            RzEdit7.Clear;
            RzEdit7.SetFocus;
            Exit;
            end
            else
            begin
              label1.Caption:='OK';
              label1.Font.Color:=clGreen;
              RzEdit8.SetFocus;
              end;
           end;
        end;
    end;
      

  3.   

          ADOTable2.Append;
          case kz4 of
            0:ADOTable2.Fields.FieldByName('one').Value:=tmp;
            1:ADOTable2.Fields.FieldByName('two').Value:=tmp;
            2:ADOTable2.Fields.FieldByName('three').Value:=tmp;
            3:ADOTable2.Fields.FieldByName('four').Value:=tmp;
            4:ADOTable2.Fields.FieldByName('five').Value:=tmp;
            5:ADOTable2.Fields.FieldByName('six').Value:=tmp;
            6:ADOTable2.Fields.FieldByName('special').Value:=tmp;
          end;
          ADOTable2.Post;
          inc(kz4);
    我这样添加能不能以判断主键来添加呢
    我这里是循环添加的   添加进去的时候就出现一个添加为一行
    我的主键是自动增长的