在一个窗口上,我用ADOQuery1与table1相连增加了一条记录。而后我打开另一窗口。想把table1的所有内容都显示出来。结果新增加的记录看不到。必须把程序重新启动后才能看到新增加的记录。。我该怎么办??

解决方案 »

  1.   

    用ADO了为什么还用TABLE呢?
    写SQL语句吧
      

  2.   

    知道啊。。就是用的sql啊table1只是一张表啊。。不是控件的。。我的代码如下:     fstr:='insert into kahao(kahao,company)values(%s,''%s'')';
         ADOQuery1.SQL.Clear;
         ADOQuery1.SQL.Add(format(fstr,[edtkahao.text,cmbcompany.text]));
         ADOQuery1.ExecSQL;
      

  3.   

    如果这样fstr:='insert into kahao(kahao,company)values(%s,''%s'')';
              ADOQuery1.SQL.Clear;
              ADOQuery1.SQL.Add(format(fstr,[edtkahao.text,cmbcompany.text]));
              ADOQuery1.ExecSQL;
    肯定看不到了,解决方法:
    1。在插入数据后
       ADOQuery1.SQL.Clear;
       ADOQuery1.SQL.Add(’查询语句‘);
       ADOQuery1.OPEN;
    2。插入不用SQL语句
       ADOQUERY1。APPEND;
       ADOQUERY1。FIELD[’‘]:=。;
       。
       。
       ADOQUERY1。POST;
      

  4.   

    好像也不行的。。我用的是SQL语句。奇怪。
      

  5.   

    fstr:='insert into kahao(kahao,company)values(%s,''%s'')';
         ADOQuery1.SQL.Clear;
         ADOQuery1.SQL.Add(format(fstr,[edtkahao.text,cmbcompany.text]));
         ADOQuery1.ExecSQL;
    adoquery1.close;ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select * from kahao');ADOQuery1.open
      

  6.   

    execsql:不返回记录
    所以在你的语句后加上:
     ADOQuery1.SQL.Clear;
     ADOQuery1.SQL.Add(select * from '表名')
     ADOQuery1.open;
    我想这样可以吧!
      

  7.   

    ADOQuery1.Append;
    ADOQuery1.FieldByName('field1').as..:=..
    ...
    ADoquery1.post;
      

  8.   

    好的。。我再详细说一下:
    1.系统工具:delphi+access;
    2。连接:   在DM上用了一个ADOConnection1进行与数据库database.mdb的相连。
    3. 在表单 frmSaleKa1 上用ADOQuery1与表SaleKa相连。用于增加一条记录。
    4. 在表单 frmSaleKa2 上用ADOTable1,DataSource1,和DBGrid1三个控件与表SaleKa相连。。把表SaleKa里的内容全部显示出来。。就这样了。当然实际比这要复杂一些。。被我简单化了。
      

  9.   

    不能再改为 Rijie(做人真难) 的方法了。。我已经用了如下的方法啊(被我简化了)。。如果改的话,几十个字段,很麻烦:     fstr:='insert into saleka(kahao,company)values(%s,''%s'')';
         ADOQuery1.SQL.Clear;
         ADOQuery1.SQL.Add(format(fstr,[edtkahao.text,cmbcompany.text]));
         ADOQuery1.ExecSQL;
      

  10.   

    增加完数据后:
    1。adotable.close;
       adotable.open;
    2。adotable.refrsh
      

  11.   

    顶!!!好的。。我再详细说一下:
    1.系统工具:delphi+access;
    2。连接:   在DM上用了一个ADOConnection1进行与数据库database.mdb的相连。
    3. 在表单 frmSaleKa1 上用ADOQuery1与表SaleKa相连。用于增加一条记录。
    4. 在表单 frmSaleKa2 上用ADOTable1,DataSource1,和DBGrid1三个控件与表SaleKa相连。。把表SaleKa里的内容全部显示出来。。就这样了。当然实际比这要复杂一些。。被我简单化了。
      

  12.   

    ADOQuery1.Active := false;
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('insert语句');
      ADOQuery1.ExecSQL;
      ADOTable1.Active := false;
      ADOTable1.Active := true;
    以上代码一定行的,如果不行,最好把你的源码拿出来让大家分析一下。
      

  13.   

    我又来了。。这个问题解决不了我可能今晚就睡不好觉了。。:那个增加记录的窗口上只有一个数据库控件:ADOQuery1。增加记录的确定按钮的代码如下:procedure TfrmSaleKa.btbtnOKClick(Sender: TObject);
    var
     fstr1:string;
     fstr2:string;
     fstr3:string;
     fstrTemp:string; timeGoujiTimestr:string;
     timeKajiTimestr:string;
     timeyuefenstr:string;begin
       if edtName.Text='' then
       MessageBox(handle,'请输入用户名称','提示',MB_ICONEXCLAMATION)
       else   if     edtkahao.Text='' then
       MessageBox(handle,'请输入卡号','提示',MB_ICONEXCLAMATION)   else if MessageDlg('请确认输入信息是否正确?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then   begin
       try
        timeGoujiTimestr:=FormatDateTime('yyyy-mm-dd',timeGoujiTime.Date);
        timeKajiTimestr:=FormatDateTime('yyyy-mm-dd',timeGoujiTime.Date);
        timeyuefenstr:=FormatDateTime('mm',timeGoujiTime.Date);      fstr1:='insert into Saleka(name,kahao,shangqiyue,huafeibiaozhun,kedahuafei,kaleibie,shoufeileibie,danwei,dianhua,dizhi,goujitime,kajitime,zhenjianleibie,zhenjiancode,baozhenjin,shoujuhao,tingjitime,xiaohutime,tuijintime,';
          fstr2:='re)values(''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',''%s'')';
          fstrtemp:=format(fstr2,[edtName.text,edtKahao.text,edtshangqiyue.text,edtHuafeibiaozhun.text,edtKedahuafei.text,cmbKaLeibei.text,cmbShoufeileibie.text,edtdanwei.text,edtdianhua.text,edtdizhi.text, timeGoujiTimestr,timeKajiTimestr,cmbZhenjianLiebie.text,edtzhenjiancode.text,edtBaozhenjin.text,edtshoujuhao.text, edttingjitime.text,edtXiaohutime.text,edttuijintime.text,edtRe.text]);      ADOQuery_SaleKa.SQL.Clear ;
          ADOQuery_SaleKa.SQL.Add(fstr1+fstrtemp);
          ADOQuery_SaleKa.ExecSQL;      MessageBox(handle,'销售卡用户信息录入成功','提示',MB_ICONEXCLAMATION);      edtname.Text:='';
          edtkahao.Text:='';
          edtdanwei.Text:='';
          edtdianhua.Text:='';
          edtdizhi.Text:='';
          edtzhenjiancode.Text:='';
          edtbaozhenjin.Text:='';
          edtshoujuhao.Text:='';
          edtshangqiyue.Text:='0';
          edtre.Text:='';      CLOSE;
          except
          MessageBox(handle,'用户信息输入错误,请检查输入的数据是否符合标准','提示',MB_ICONSTOP);
        end;
       end;
     end;