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