/// <summary> /// 数据库是否存在 /// </summary> public Boolean dbExists(String dbName) { bool exist = false; using (var dr = SQLServerHelper.ExecuteReader( String.Format(connectionString3, dataSource), String.Format(Sql.DB_EXISTS, Path.GetFileNameWithoutExtension(dbName), Path.GetDirectoryName(dbName)), CommandType.Text)) { exist = dr != null && dr.HasRows; } // 数据库文件被手动删除,drop一次 if (exist && !File.Exists(dbName)) { try { SQLServerHelper.ExecuteNonQuery( String.Format(connectionString3, dataSource), String.Format(Sql.DELETE_DB, Path.GetFileNameWithoutExtension(dbName)), CommandType.Text); } catch (SqlException) { } finally { exist = false; } } return(exist); }
/// <summary> /// 当前连接,是否存在表 /// </summary> public Boolean tableExists(String dbName, String tableName) { using (var dr = SQLServerHelper.ExecuteReader( String.Format(connectionString1, dataSource), String.Format(Sql.TABLE_EXISTS, tableName), CommandType.Text)) { return(dr != null && dr.HasRows); } }
public Boolean IsExist(String username) { using (var dr = SQLServerHelper.ExecuteReader( String.Format(connectionString1, getDBName()), String.Format("select count(*) from {0} where UserName='******'", this.getTableName(), username), CommandType.Text)) { return((dr != null && dr.Read()) ? dr.GetInt32(0) != 0 : false); } }
/// <summary> /// 获取数据库中所有表名 /// </summary> public List <String> getTableNames(String dbName) { List <String> tables = new List <String>(); var dr = SQLServerHelper.ExecuteReader( String.Format(connectionString1, dataSource), Sql.GET_ALL_TABLE_NAME, CommandType.Text); while (dr != null && dr.Read()) { tables.Add(dr[0].ToString()); } return(tables); }
public Boolean IsMatch(User user) { if (user == null) { return(false); } using (var dr = SQLServerHelper.ExecuteReader( String.Format(connectionString1, getDBName()), String.Format("select count(*) from {0} where UserName={1} and PassWord={2}", this.getTableName(), user.UserName, user.PassWord), CommandType.Text)) { return((dr != null && dr.Read()) ? dr.GetBoolean(0) : false); } }