2023年6月21日发(作者:)

SQL语句判断1、 ///

/// 判断是否存在某表的某个字段 /// /// 表名称 /// 列名称 /// 是否存在 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 32(res) > 0; }//带参数的SQL /// /// 删除 /// /// /// public int Delete(int id) { string sql = @"DELETE FROM ProjectProcedure WHERE ID=@ID"; SqlParameter[] parameters = new SqlParameter[]{new SqlParameter("@ID", ){ Value = id }}; return e(sql, parameters); }创建表之前先判断数据库是否存在该表,如果存在就先删除再创建if exists (select * from sysobjects where name = 'ContractCategory')drop table ContractCategory

create table ContractCategory

( ID Int identity(1,1) primary key,-- Name Varchar(50), --类别名称)go

2023年6月21日发(作者:)

SQL语句判断1、 ///

/// 判断是否存在某表的某个字段 /// /// 表名称 /// 列名称 /// 是否存在 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 32(res) > 0; }//带参数的SQL /// /// 删除 /// /// /// public int Delete(int id) { string sql = @"DELETE FROM ProjectProcedure WHERE ID=@ID"; SqlParameter[] parameters = new SqlParameter[]{new SqlParameter("@ID", ){ Value = id }}; return e(sql, parameters); }创建表之前先判断数据库是否存在该表,如果存在就先删除再创建if exists (select * from sysobjects where name = 'ContractCategory')drop table ContractCategory

create table ContractCategory

( ID Int identity(1,1) primary key,-- Name Varchar(50), --类别名称)go