Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

Can anyone know.

it show error like ,'string' does not contain a definition for 'IsNullOrWhiteSpace' how to solve this error?

C#
public object SQLExecuteNonQuery(string procedureName, Hashtable cmdParms)
   {
       try
       {
           _SqlConnection = GetSQLConnection();
           //Open SQL Connection
           _SqlConnection.Open();
           _SqlCommand = new SqlCommand(procedureName, _SqlConnection);

           _SqlCommand.CommandType = CommandType.StoredProcedure;
           //null or empty checking procdure name and hashtable
           if (cmdParms.Count > 0 && !string.IsNullOrWhiteSpace(procedureName))
           {
               foreach (DictionaryEntry de in cmdParms)
               {
                   //adding sql parameter
                   _SqlCommand.Parameters.Add(new SqlParameter(de.Key.ToString(), de.Value));
               }

           }
           //Executing SQl Command
           return _SqlCommand.ExecuteScalar();
       }
Posted

string.IsNullOrWhiteSpace was added to .net framework 4.0 and up. So you must be using older version of .net framework. Set the appropriate .net framework in your project settings. See here[^].
 
Share this answer
 
Comments
Espen Harlinn 8-Feb-12 9:25am    
5'ed!
Tech Code Freak 8-Feb-12 12:45pm    
5up!
Looks like you are trying to build code in an older version of .Net.
Anything before .Net 4.0 does not support this method.
 
Share this answer
 
Comments
Espen Harlinn 8-Feb-12 9:25am    
5'ed!
Abhinav S 8-Feb-12 9:28am    
Thanks.
Tech Code Freak 8-Feb-12 12:45pm    
5up!
String.IsNullOrWhiteSpace has been introduced in .NET 4. If you are not targeting .NET 4 you could easily write your own:


C#
public static class StringExtensions
{
    public static bool IsNullOrWhiteSpace(string value)
    {
        if (value != null)
        {
            for (int i = 0; i < value.Length; i++)
            {
                if (!char.IsWhiteSpace(value[i]))
                {
                    return false;
                }
            }
        }
        return true;
    }
}


which could be used like this:

bool isNullOrWhiteSpace = StringExtensions.IsNullOrWhiteSpace("foo bar");
 
Share this answer
 
v2

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