【发布时间】:2017-06-14 18:00:34
【问题描述】:
我有一个使用 NpgSQL 与 postgres 数据库通信的 C# 应用程序。但是,当我尝试使用包含 NULL 值的结果填充 DataTable 时,会引发错误:
"System.Data.ConstraintException: '未能启用约束。一行或多行包含违反非空、唯一或外键约束的值。'"
即使我做了类似的事情:
NpgsqlCommand statement = new NpgsqlCommand("SELECT NULL", connection);
NpgsqlDataReader resultReader = statement.ExecuteReader();
var table = new DataTable();
table.Load(resultReader);
在 Visual Studio 命令窗口中,table.GetErrors()[0]` 给出:
{System.Data.DataRow}
HasErrors: true
ItemArray: {object[1]}
RowError: "Column '?column?' does not allow DBNull.Value."
RowState: Unchanged
Table: {}
这可能与this bug有关吗?
【问题讨论】:
标签: c# postgresql datatable npgsql