Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


C#
IDTextBox.Text = "";
IDTextBox.Text = null;


On Form Load event, I have following code.


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


I am using following code to save new record in database

C#
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


C#
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.
Posted
Updated 9-Sep-16 23:43pm
v3

1 solution

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!
 
Share this answer
 
Comments
Member-ammar 10-Sep-16 5:47am    
The code is pretty simple. I have edited and tried to explain it in more detail.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900