What did you mean by nothing changed? Do you still have to insert a null value manually or the default null value can't be inserted into database? Thanks.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Dev.Bassem
Member
6 Points
20 Posts
Parameters and Null Values ..!
Sep 27, 2010 05:20 AM|LINK
Hi There,
I was develop an application (ASP.Net) Using (VS.Net C# 2010 & SQL Server 2008)
And I was applying (3-tyer Basics) and I'm not using wizard forever in my application.
The problem is :
When I try to passing the parameters to database, some fields I don't type it
But it's show in database (Empty like "Space") in text fields and (01-01-1900) in date fields
Although it's must be (Null) .
How I can pass parameters with Null Values for the fields that's not typed ?
Thanks in advanced
asp.net ADO.NET null parameter
gopalanmani
Star
7826 Points
1320 Posts
Re: Parameters and Null Values ..!
Sep 27, 2010 08:26 AM|LINK
Hi,
check this thread,
http://www.c-sharpcorner.com/UploadFile/sd_patel/EnterNullValuesForDateTime11222005015742AM/EnterNullValuesForDateTime.aspx
and also the following c# code sample shows how to pass Null as a parameter value.
SqlParameter ParamValue= new SqlParameter("@Address", SqlDbType.NVarChar, 20);
ParamValue.Value = DBNull.Value;
Gopalan Mani
My Tech blog
Dev.Bassem
Member
6 Points
20 Posts
Re: Parameters and Null Values ..!
Sep 27, 2010 08:22 PM|LINK
Hi,
thanks for your help, but in this way i need to write many lines of (if statements)
why it's don't work already when i didn't type in the field ?
,, Regards
Dev.Bassem
Member
6 Points
20 Posts
Re: Parameters and Null Values ..!
Sep 29, 2010 05:48 AM|LINK
up
Mohamed.Elkh...
Member
6 Points
3 Posts
Re: Parameters and Null Values ..!
Sep 29, 2010 08:28 AM|LINK
Assuming that your parameter name is 'parameter', you could use :
parameter.Value = DBNull.Value
Mark as answered if it is helpful.
Thanks
Egypt, Damietta
Technical Team Leader
Microsoft Certified Professional
http://mohamedelkhodary.blogspot.com/
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: Parameters and Null Values ..!
Sep 30, 2010 08:11 AM|LINK
Hi dev.bassem,
For your requirements, it's better to set the default value as null in database so that you'll have no need to set it as null in source code.
Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Dev.Bassem
Member
6 Points
20 Posts
Re: Parameters and Null Values ..!
Sep 30, 2010 09:49 PM|LINK
<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;" mce_style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">Hi there,
Thanks for your help but Nothing change .
,, Regards
</div>Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: Parameters and Null Values ..!
Oct 01, 2010 06:24 AM|LINK
What did you mean by nothing changed? Do you still have to insert a null value manually or the default null value can't be inserted into database? Thanks.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Dev.Bassem
Member
6 Points
20 Posts
Re: Parameters and Null Values ..!
Oct 01, 2010 06:46 AM|LINK
Hi,
The Problem is when i try to save record to the database some fields i didn't type any thing in it
but it's passing to the database as (Space or Empty) .
,, Regards
Wencui Qian ...
All-Star
56784 Points
5796 Posts
Microsoft
Re: Parameters and Null Values ..!
Oct 01, 2010 06:54 AM|LINK
Then how did you set it in database?
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework