Click here to Skip to main content
16,015,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if our textbox is empty the how can we store null or nothing in database
C#
if (MyTextBox.Text == String.Empty)
{
   // the textbox is empty
   cmd.Parameters.Add("@per_m", SqlDbType.Float).Value =    ;

}
Posted
Updated 6-Mar-11 5:42am
v2

Try
<code>
cmd.Parameters.AddWithValue("@per_m", MyTextBox.Text.Trim() == String.Empty ? DBNull.Value : (object)MyTextBox.Text);
</code>
 
Share this answer
 
http://msdn.microsoft.com/en-us/library/system.dbnull.aspx[^]

I hope the above information will be helpful. If you have more concerns, please let me know.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Mar-11 13:54pm    
Sure, a 5 -- should be enough.
--SA
Monjurul Habib 7-Mar-11 1:54am    
thanx for your appreciation.
Try:
cmd.Parameters.Add("@per_m", SqlDbType.Float).Value = System.DBNull.Value;
 
Share this answer
 
Comments
Shagun Bansal 6-Mar-11 8:51am    
cmd.Parameters.Add("@per_m", SqlDbType.Float).Value = System.DBNull.Value;
Failed to convert parameter value from a String to a Double.
this error comes
Sergey Alexandrovich Kryukov 6-Mar-11 13:54pm    
Good, a 5.
--SA

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