示例#1
0
        public T QuerySingle <T>()
        {
            SqlCommand Command = new SqlCommand(Sql, (SqlConnection)_Connection);

            if (_Transaction != null)
            {
                Command.Transaction = (SqlTransaction)_Transaction;
            }

            //init Command to execute
            Command.CommandType = commandType;
            foreach (Parameter P in Parameters)
            {
                Command.Parameters.Add(new SqlParameter(P.Name, (P.value == null ? DBNull.Value : P.value)));
            }

            T OutPutRecord = (T)Activator.CreateInstance(typeof(T));

            SqlDataReader Dr = Command.ExecuteReader();

            //-----
            SureConnectionAlive();

            Utilities.ClassValue objClassValue = new Utilities.ClassValue();

            //----Start Read Data
            while (Dr.Read())
            {
                OutPutRecord = objClassValue.SetClassValues <T>(Dr);
            }

            Dr.Close();
            return(OutPutRecord);
        }
示例#2
0
        public List <T> Query <T>()
        {
            SqlCommand Command = new SqlCommand(Sql, (SqlConnection)_Connection);

            if (_Transaction != null)
            {
                Command.Transaction = (SqlTransaction)_Transaction;
            }

            //init Command to execute
            Command.CommandType = commandType;
            foreach (Parameter P in Parameters)
            {
                Command.Parameters.Add(new SqlParameter(P.Name, (P.value == null ? DBNull.Value : P.value)));
            }


            List <T> OutPutRecords = new List <T>();

            SqlDataReader Dr = Command.ExecuteReader();

            //-----
            SureConnectionAlive();

            Utilities.ClassValue objClassValue = new Utilities.ClassValue();

            //----Start Read Data
            while (Dr.Read())
            {
                T ClassRecord = objClassValue.SetClassValues <T>(Dr);

                //Add To OutPut Records
                OutPutRecords.Add((T)ClassRecord);
            }

            Dr.Close();
            return(OutPutRecords);
        }