Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one

I am new to linq. i Have a sql table, having 10 columns out of which 3 are set to allow null. Now in C# i am using Linq. When the user leaves empty text boxes the
where i have a table having 3 colums with null allow. In C# code i am using linq In the object initializer code i am assigning the text box values to the corresponding property of the table class, When i left the text box blank then it inserts space in sql table. but i need null there. So how can i make it possible to have null if the user doesn't input into the corresponding text boxes


Help or guidance is needed
Thanks in advance
Posted

1 solution

I assume by "space", you mean "empty string". Perhaps you are just looking to do something like this:
C#
string dbField = (txtInput.Text == "" ? null : txtInput.Text);
 
Share this answer
 
Comments
TanzeelurRehman 14-Jan-12 4:51am    
But I modified the setter property with && statement in the .designer.cs.That if the value is String.Empty, Then setter do nothing, otherwise it will update the property what in the text box

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