Skip to content

Return null from function

Ajay Singh

Asked Aug 23, 2006, 1:21 PM EDT1 answer
Share
LinkedInX
I have some textboxes.  I want to read their value and find if they are null or not.  If the value is empty I want to return null as I will be creating a dynamic insert Sql statement.  I created the Datahelper class with various functions like

public static string GetString(string text)   //text value comes from TextBox.Text
{
if ((text == null) || (text.Trim().Length == 0))
{
return string.Empty;
}
//return null;
// System.DBNull.Value;

return text;
}
This is giving me ""and not null.  I want to store null in database and not "".  

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    try once at

     return DBNull.Value.ToString();
    0