We Help You To Renovate Your Blogger Blog With Awesomeness!

Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, October 26, 2014

  • How to convert DateTime to Date VarChar





    This line of code do the job


    CONVERT(varchar(10), [MyDateTimecolumn], 20)
     
     
    eg: select PKID,CONVERT(varchar(10), createdDate, 20) from tempTable
     
     
     
     
     
  • Best way to check if a Data Table has a null (SQL) value in it


    Hostgator Offers


     Check Whole table



    If you want to check if a null value exists in the table you can use this method:
    public static bool HasNull(this DataTable table)
    {
        foreach (DataColumn column in table.Columns)
        {
            if (table.Rows.OfType<DataRow>().Any(r => r.IsNull(column)))
                return true;
        }
    
        return false;
    }
     
     
    and use 
     
    table.HasNull(); 


     where ever you need


     Checking Specific column


    Compare the value of the column to the DBNull.Value value to filter and manage null values in whatever way you see fit.

     
     
     
     
    foreach(DataRow row in table.Rows)
    {
        object value = row["ColumnName"];
        if (value == DBNull.Value)
            // do something
        else
            // do something else
    }
     
     
    Check More About DBNull Class
     
     
     
     
  • Copyright @ 2013 Code Snippets.