datagrid 复选框将 Null 而不是 0 (false) 写入数据库

2023-02-19数据库问题
7

本文介绍了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) 写入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

sql group by 与不同
sql group by versus distinct(sql group by 与不同)...
2024-04-16 数据库问题
37

如何在SQL中返回每个组的增量组号
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)...
2024-04-16 数据库问题
8

统计分组返回的记录数
Count number of records returned by group by(统计分组返回的记录数)...
2024-04-16 数据库问题
10

带聚合函数的 SQL GROUP BY CASE 语句
SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)...
2024-04-16 数据库问题
23