示例#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 dynamic QuerySingleDynamic()
        {
            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)));
            }

            SqlDataReader Dr = Command.ExecuteReader();

            //-----
            SureConnectionAlive();

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

            //----Start Read Data
            while (Dr.Read())
            {
                dynamic dynamicOutPut = new ExpandoObject();
                var     dictionary    = (IDictionary <string, object>)dynamicOutPut;
                for (int i = 0; i < Dr.FieldCount; i++)
                {
                    dictionary.Add(Dr.GetName(i), Dr[i]);
                }
                Dr.Close();
                return(dynamicOutPut);
            }
            Dr.Close();
            return(null);
        }
示例#3
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);
        }