我如何在不清除其字段的情况下将记录附加到Tadoquery?

发布于 2025-01-24 17:47:08 字数 969 浏览 1 评论 0原文

我正在使用tadoquery带有批量锁定类型的tadoquery。如果Select命令具有在数据库服务器上计算的一些字段,则返回字段具有ReadOnly = true的属性,因此我必须将它们更改为False,以便我可以在查询中对其进行修改。

实际上,我从来没有尝试过发布数据库,但是我必须使用tadoquery。

这一切都很好,我附加或插入一些记录,设置其字段,然后致电例如tadoquery.last,下一个或第一个。拜托,有什么方法可以按原样保留这些记录?

我在这里附上一个简单的代码,其中提出了问题:

      // .. lockType = Batchoptimistic so TAdoQuery.first or TAdoQuery.last do NOT post do database
      ADOQuery1.LockType := ltBatchOptimistic;
      ADOQuery1.SQL.Text := 'SELECT 10 AS id, 20 AS sid ';
      ADOQuery1.Open;
    
      // .. readOnly = false so i can modify these two fields in appended record
      ADOQuery1.FieldByName('id').ReadOnly := false;
      ADOQuery1.FieldByName('sid').ReadOnly := false;
      ADOQuery1.Append;
    
      ADOQuery1.FieldByName('id').AsInteger := 5;
      ADOQuery1.FieldByName('sId').AsInteger := 5;
    
      // if use last, first  etc. the appended record fields will change to 0 (null)
      ADOQuery1.Last;

I am using TAdoQuery with BatchOptimistic lock type. If the select command has some fields that are calculated on database server the returned fields has property ReadOnly = true, so i must change them to false so i can modify them in my query.

I am actually never attempting to post to database, but i must use TAdoQuery.

Its all good to the point I append or insert some record, set its fields, and then call for example TAdoQuery.Last, Next or First.. The appended records fields change to null. Please, is there a way that these records could stay as they were?

I am attaching a simple code here, where the problem is presented:

      // .. lockType = Batchoptimistic so TAdoQuery.first or TAdoQuery.last do NOT post do database
      ADOQuery1.LockType := ltBatchOptimistic;
      ADOQuery1.SQL.Text := 'SELECT 10 AS id, 20 AS sid ';
      ADOQuery1.Open;
    
      // .. readOnly = false so i can modify these two fields in appended record
      ADOQuery1.FieldByName('id').ReadOnly := false;
      ADOQuery1.FieldByName('sid').ReadOnly := false;
      ADOQuery1.Append;
    
      ADOQuery1.FieldByName('id').AsInteger := 5;
      ADOQuery1.FieldByName('sId').AsInteger := 5;
    
      // if use last, first  etc. the appended record fields will change to 0 (null)
      ADOQuery1.Last;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文