passing null to database using C#
I have a null able integer in database table. I want to pass a null value from C# to database table. How can i able to do that. If any one knows about it then please help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
waqar laghariPosted May 19, 2009, 11:17 PM
Dear I have tried your solution but it is not working properly.. I am again repating my question?..
I want to insert a null data in a column which is define as int by using insert qurey.. any brother have some idea about it then please share it. because your idea may work for me.... Thanks in advance
zirano lattPosted May 19, 2009, 6:12 AM
the use of nullable int is as follows;
int i = null; // compile error value type can't be null
int? i=null; // no error as int? is nullable int value type.
If your C# version is lower than V3.0, may be you can consider the following work around.
if(i==0) insert null
else insert i