zoukankan      html  css  js  c++  java
  • sql 2005判断某个表或某个表中的列是否存在

    /// <summary>
            /// 判断是否存在某表的某个字段
            /// </summary>
            /// <param name="tableName">表名称</param>
            /// <param name="columnName">列名称</param>
            /// <returns>是否存在</returns>
            public static bool ColumnExists(string tableName, string columnName)
            {
                string sql = "select count(1) from syscolumns where [id]=object_id('" + tableName + "') and [name]='" + columnName + "'";
                object res = GetSingle(sql);
                if (res == null)
                {
                    return false;
                }
                return Convert.ToInt32(res) > 0;
            }

    /// <summary>
            /// 表是否存在
            /// </summary>
            /// <param name="TableName"></param>
            /// <returns></returns>
            public static bool TabExists(string TableName)
            {
                string strsql = "select count(*) from sysobjects where id = object_id(N'[" + TableName + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1";
                //string strsql = "SELECT count(*) FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + TableName + "]') AND type in (N'U')";
                object obj = GetSingle(strsql);
                int cmdresult;
                if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
                {
                    cmdresult = 0;
                }
                else
                {
                    cmdresult = int.Parse(obj.ToString());
                }
                if (cmdresult == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

  • 相关阅读:
    jQuery中的Deferred详解和使用
    Windows Server 2003 无法布署.NET Framework4.5 应用解决方案
    jquery 获取父窗口的元素、父窗口、子窗口
    Android USB HOST API
    ASP.NET MVC+Vue.js实现联系人管理
    Vue在ASP.NET MVC中的进行前后端的交互
    JS中 “is not defined” 如何判断defined,defined和undefined 的区别
    Android自定义view实现个人中心设置界面带点击事件
    java 正则表达式(内附例子)
    在asp.net mvc 中使用Autofac
  • 原文地址:https://www.cnblogs.com/soundcode/p/2511092.html
Copyright © 2011-2022 走看看