示例#1
0
        /// <summary>
        /// 执行选择操作,返回SqlDataReader
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="creator"></param>
        /// <returns></returns>
        public static SqlDataReader SelectReader(string connectionString, SqlCreator creator)
        {
            string sql = creator.GetSelectSql();
            var par = new SqlParameter[creator.WhereColumns.Length];
            for (int i = 0; i < creator.WhereColumns.Length; i++)
            {
                Column parm = creator.WhereColumns[i];
                par[i] = MakeInputParam(parm.ParameterName, parm.DbType, parm.Size, parm.Value);
            }

            return ExecuteReader(connectionString, CommandType.Text, sql, par);
        }
示例#2
0
        /// <summary>
        /// 判断是否存在一条记录
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="creator">判断条件</param>
        /// <returns></returns>
        public static bool Exists(string connectionString, SqlCreator creator)
        {
            creator.Columns = new[]
                                  {
                                      new Column("count(1)")
                                  };

            var par = new SqlParameter[creator.WhereColumns.Length];
            for (int i = 0; i < creator.WhereColumns.Length; i++)
            {
                Column parm = creator.WhereColumns[i];
                par[i] = MakeInputParam(parm.ParameterName, parm.DbType, parm.Size, parm.Value);
            }

            object obj = ExecuteScalar(connectionString, CommandType.Text,
                                       creator.GetSelectSql(),
                                       par);

            int count = int.Parse(obj.ToString());

            return count > 0;
        }