Tuesday, September 6, 2011

Table Name Exist or not in Database


This function can use to check TableName exist or not in Database:-
if return value of function is 1 that means table exist in database.
public int TableExist(String TableName)
        {
            DataTable dt = new DataTable();
            try
            {
                DB.Open();
                String[] restriction=new String[3];
                restriction[2] = TableName;
                dt = DB.GetSchema("Tables", restriction);
                if (dt.Rows.Count == 0)
                {
                    DB.Close();
                    return 0;
                }
                else
                {
                    DB.Close();
                    return 1;
                }
               
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.ToString());
                DB.Close();
            }
            return 0;
        }

No comments:

Post a Comment