예제 #1
0
        /// <summary>
        /// 创建表
        /// </summary>
        public Boolean createTable(String dbName, String tableName, Type type)
        {
            Int32 row = SQLServerHelper.ExecuteNonQuery(
                String.Format(connectionString1, dataSource),
                String.Format(Sql.CREATE_TABLE, tableName, getTableColumnDefinition(type)),
                CommandType.Text);

            //using (var dr = SQLServerHelper.ExecuteReader(
            //    String.Format(connectionString1, dataSource),
            //    String.Format(Sql.CREATE_TABLE, getFullTableName(dbName, tableName), getTableColumnDefinition(type)),
            //    CommandType.Text)) {}
            return(tableExists(dbName, tableName));
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        public Boolean Insert(User user)
        {
            if (user == null)
            {
                return(false);
            }
            // SQL拼接
            Int32 recordsAffected = SQLServerHelper.ExecuteNonQuery(
                String.Format(connectionString1, getDBName()),
                String.Format("insert into {0} ({1}) values ({2})",
                              this.getTableName(), this.getFieldString(String.Empty), this.getValueString(user, "'")),
                CommandType.Text);

            return(recordsAffected > 0);
        }
예제 #5
0
        /// <summary>
        /// 创建数据库
        /// </summary>
        public void createDB(String dbName)
        {
            // 查询数据库是否存在
            bool exist = dbExists(dbName);

            if (!exist)
            {
                // 创建数据库
                SQLServerHelper.ExecuteNonQuery(
                    String.Format(connectionString3, dataSource),
                    String.Format(Sql.CREATE_DB, Path.GetFileNameWithoutExtension(dbName), dbName.Replace(".MDF", "")),
                    CommandType.Text);
                // 数据库是否创建成功
                exist = File.Exists(dbName);
            }
        }