Friday, May 1, 2015

asp.net check is date

 public static bool IsDate(string s)
        {
            try
            {
                DateTime.Parse(s);
            }
            catch
            {
                return false;
            }
            return true;
        }

asp.net check is numeric

  public static bool IsNumeric(string s)
        {
            try
            {
                Decimal.Parse(s);
            }
            catch
            {
                return false;
            }
            return true;
        }

asp.net convert to string

  public static string ToString(object value)
        {
            if (IsDBNull(value))
                return "";
            else if (value == "")
                return "";
            else
                return (Convert.ToString(value));
        }

asp.net check is DBNull

    public static bool IsDBNull(object value)
        {
            if (value is DBNull)
                return true;
            else
                return false;
        }

asp.net convert string to byte

 public static byte[] StringToByte(string str)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return encoding.GetBytes(str);
        }

asp.net convert byte to string

 public static string ByteToString(Object byteObject)
        {
            string returnString;
            byte[] byteValue;
            try
            {
                if (byteObject.GetType().ToString() == "System.Byte[]")
                {
                    byteValue = (byte[])byteObject;
                    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                    returnString = asciiEncoding.GetString(byteValue);
                }
                else
                    returnString = byteObject.ToString();
            }
            catch (BaseException ex)
            {
                throw ex;
            }
            return returnString;
        }

sql change table column data type

alter table mst_school_details
alter column sport_equipment varchar(50)