datagrid checkbox writes Null instead of 0 (false) into database(datagrid 复选框将 Null 而不是 0 (false) 写入数据库)
问题描述
我的 sql 数据库中有一个表,其中包含以下字段:名称(字符串)、Quartal1(位)、Quartal2(位)、Quartal3(位)、Quartal4(位).
I have a Table in my sql-database that has the following fields: Name(string), Quartal1(bit), Quartal2(bit), Quartal3(bit), Quartal4(bit).
我将该表绑定到数据网格(visual studio 中的 winform).我为每个 Quartal 设置了一个复选框,并将数据集保存到我的数据库中.它实际上工作它写入一个 1 以检查到我的数据库但它写入一个 NULL 而不是 0(对于 false)到我的数据库中以进行未检查.我试图改变FalseValue"&TrueValue"属性为FALSE"和TRUE"或0"和1",但它没有帮助.我还将字段属性NULLS ALLOWED"更改为NULLS NOT ALLOWED",但这也无济于事.因为我需要一个 0 来表示未检查,所以我需要你的帮助来完成它.
I bound that Table to a datagrid (winform in visual studio). I have a Checkbox for every Quartal and save the dataset into my database. It works actually it writes a 1 for checked into my database BUT it writes a NULL instead of a 0 (for false) into my database for unchecked. I tried to change the "FalseValue" & "TrueValue" property to "FALSE" and "TRUE" or "0" and "1" but it doesnt help. I also changed the field property "NULLS ALLOWED" to "NULLS NOT ALLOWED" but that didnt help as well. Since i need a 0 for not checked i need your help to accomplish that.
推荐答案
好吧,没用.有帮助的是我创建了一个新数据集并使用了设计器视图.在这里,您可以将默认值(默认值类似于 )设置为我需要的值(在本例中为 0).现在它将值写入数据库.
Ok, it didnt work. What helped was that i created a new dataset and used the designer-view. Here you can set a default value (default was something like ) to the one i needed (in this case 0). Now it writes the value into the database.
这篇关于datagrid 复选框将 Null 而不是 0 (false) 写入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:datagrid 复选框将 Null 而不是 0 (false) 写入数据库
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
