winform中的Int字段不使用C#更新SQL Server数据库中的空值 [英] Int field in winform does not update null values in SQL server database using C#

查看:135
本文介绍了winform中的Int字段不使用C#更新SQL Server数据库中的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In my Winforms C# application, I have fields with Int data type and they are set to accept null values in SQL Server database (allow nulls).

In the forms I have some textboxes which are bound to those int data type fields. If I don't enter anything while creating a new record, it accepts and saves record in sql database. If I enter a number in the textbox, it also accepts it, and then if I delete the number, it doesn't allow me to move to the next field.

If I set its value as null or "" through code, it is not updated in database and even does not update changes which I made in other non int text fields (this update works fine if I dont touch int fields).
 
I am using following to enter null in this field.







IDTextBox.Text = "";
IDTextBox.Text = null;







On Form Load event, I have following code.







this.itemsTableAdapter.Fill(this.sBSDBDataSet.Items);







I am using following code to save new record in database




this.itemsbindingSource.AddNew();
this.Validate();
this.itemsbindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.sBSDBDataSet);




On this form there are many fields in which I enter data and then press UPDATE button to update the record in SQL Server database. I am using following method to update the record







this.Validate();
this.itemsbindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.sBSDBDataSet);







All other fields seem to work fine except the fields having int datatype (although in sql table I have allowed them to be null).
.

As I mentioned above, int field text box on WinForm does not even allow to move to next field during data entry if we do not enter something in it

What can I do for the textbox accept null values?





我尝试过:



我搜索了很多,但找不到任何解决方案来解决我的问题。



What I have tried:

I have googled a lot but did not find any solution to solve my problem.

推荐答案

检查你的Validate方法:它允许一个空条目?

如果一切正常,那么使用调试器来完全按照正在发生的事情 - 当前你似乎没有任何信息可以使用,因为我们可以甚至没有看到你的代码,更不用说了我们甚至更少的代码!
Check your Validate method: it is allowing an empty entry?
If it all looks right, then use the debugger to follow exactly what is going on - at the moment you don't appear to have any information to work from, and since we can't even see your code, much less run it we have even less to work with!


这篇关于winform中的Int字段不使用C#更新SQL Server数据库中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆