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

datagrid checkbox writes Null instead of 0 (false) into database(datagrid 复选框将 Null 而不是 0 (false) 写入数据库)
本文介绍了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) 写入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending parameters to stored procedures vb.net(将参数发送到存储过程 vb.net)
Insert multiple rows, count based on another table columns(插入多行,根据另一个表列计数)
How to hold the location of an image in a SQL Server database?(如何在 SQL Server 数据库中保存图像的位置?)
How to send to email (outlook) the selected items in SQL Server database using vb.net(如何使用 vb.net 将 SQL Server 数据库中的选定项目发送到电子邮件(Outlook))
DBCC CheckDb-any ways to detect errors vb.net?(DBCC CheckDb-vb.net 有什么检测错误的方法吗?)
one table is available in Presentation Tier, the other is not(一张表在 Presentation Tier 中可用,另一张不可用)