I am trying to use a TAdoquery with MS SQL Server in a legacy delphi project. The dataset contains a field that represents identity column in the SQL table. It has AutogenerateValue = arAutoInc
and ProviderFlags [pfInWhere, pfInKey]
. It also has Required = false
.
我试图在遗留的delphi项目中使用TAdoquery和MS SQL Server。数据集包含一个表示SQL表中标识列的字段。它有AutogenerateValue = arAutoInc和ProviderFlags [pfInWhere,pfInKey]。它还具有Required = false。
After doing adoquery.Append
I prefill fields and try to do adoquery.Post
but get this error: Non-nullable column cannot be updated to Null
做了adoquery.Append我预填充字段并尝试做adoquery.Post但得到这个错误:不可为空的列无法更新为Null
All non-nullable fields are set to non-null before post, so the identity column is the only suspect. The TADOQuery has no joins (simple Select * from my_table), but it has look up fields and calculated fields, which may be null. For lookup fields and calculated fields I removed provider Flags to ensure those fields do not appear in the insert or update statement.
发布之前,所有非可空字段都设置为非null,因此标识列是唯一的可疑项。 TADOQuery没有连接(简单的Select * from my_table),但它查找了字段和计算字段,可能为空。对于查找字段和计算字段,我删除了提供程序标志,以确保这些字段不会出现在insert或update语句中。
The identity field is NULL immediately before post, I see no insert command firing on the server in the Profiler, instead I just get this error.
标识字段在发布之前立即为NULL,我看不到在Profiler中服务器上没有插入命令,而是我刚刚收到此错误。
- Is it possible to preview the sql statement generated by the Tadoquery to insert a new row ?
- 是否可以预览由Tadoquery生成的sql语句来插入新行?
1 个解决方案
#1
0
I solved it, the issue was of course unrelated to the identity column. The initial sql was select * from myTable
, which meant that it also loaded a couple of extra columns that were not bound to any grid column in my DBGridEh. After replacing * with an explicit list of the columns that I needed the INSERT worked.
我解决了这个问题,这个问题当然与身份栏无关。最初的sql是来自myTable的select *,这意味着它还加载了几个未绑定到我的DBGridEh中的任何网格列的额外列。用我需要的列的明确列表替换*之后INSERT工作了。
#1
0
I solved it, the issue was of course unrelated to the identity column. The initial sql was select * from myTable
, which meant that it also loaded a couple of extra columns that were not bound to any grid column in my DBGridEh. After replacing * with an explicit list of the columns that I needed the INSERT worked.
我解决了这个问题,这个问题当然与身份栏无关。最初的sql是来自myTable的select *,这意味着它还加载了几个未绑定到我的DBGridEh中的任何网格列的额外列。用我需要的列的明确列表替换*之后INSERT工作了。