我使用Delphi做有关数据库的软件,向数据库添加记录时报错说:"Q_addnote:cannot perform this operation on a closed dataset".代码如下:
  Q_addnote.Close;
  Q_addnote.SQL.Clear;
  Q_addnote.Append;
  Q_addnote.FieldByName('date').AsString:=Date_str;
  Q_addnote.FieldByName('type').AsString:=Type_str;
  Q_addnote.FieldByName('subdiv').AsString:=Subdiv_str;
  Q_addnote.FieldByName('money').AsString:=Money_str;
  Q_addnote.Open;
  Q_addnote.Post;
不知是什么原因,情高手帮下忙,谢谢!

解决方案 »

  1.   

    Q_addnote.Close; {关闭了,如何新增?}
      Q_addnote.SQL.Clear; {连SQL.TEXT也清了,不错才怪呢}
      

  2.   

    设置sql->open->append->post
    顺序要搞清楚还有,提示的英文很易懂的吧.
      

  3.   

    因为写SQL语句报错才改成上边的方法不清楚下边的语句有什么错:
    Q_addnote.SQL.Add('insert into total(date,type,subdiv,money) values ('''+Date_str+''','''+Type_str+''','''+Subdiv_str+''','''+Money_str+''')');
      

  4.   

      Q_addnote.Close; 
      Q_addnote.SQL.Clear; 
      Q_addnote.SQL.text := ..........
      Q_addnote.Open; 
      Q_addnote.Append; 
      Q_addnote.FieldByName('date').AsString:=Date_str; 
      Q_addnote.FieldByName('type').AsString:=Type_str; 
      Q_addnote.FieldByName('subdiv').AsString:=Subdiv_str; 
      Q_addnote.FieldByName('money').AsString:=Money_str; 
      Q_addnote.Post; 
      

  5.   

    以下语句报错:"操作必须使用一个可更新的查询"     Q_stat.Close;
        Q_stat.SQL.Clear;
        Q_stat.SQL.Add('update type set stat=(select sum(money) from total where '
        +'total.subdiv = type.subdiv and date between '''+time1+''' and '''+time2+''')');
        Q_stat.ExecSQL;是什么原因?