コード例 #1
0
        public Employee GetEmployee(int employeeId)
        {
            Employee e = new Employee();

            using (SqlConnection conn = DB.GetSqlConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"GetEmployeeDetails";
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    SqlParameter p1 = new SqlParameter("businessEntityId", System.Data.SqlDbType.Int);
                    p1.Value = employeeId;

                    cmd.Parameters.Add(p1);

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        e.Load(reader);
                    }
                }
            }
            return(e);
        }
コード例 #2
0
        public Employee GetEmployeeDONOTCALL(int employeeId)
        {
            Employee e = new Employee();

            using (SqlConnection conn = DB.GetSqlConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"select * from HumanResources.Employee E
			                            JOIN Person.Person P ON E.BusinessEntityId = P.BusinessEntityId AND P.PersonType = 'EM'
			                            JOIN HumanResources.EmployeeDepartmentHistory EH ON E.BusinessEntityId = EH.BusinessEntityId
			                            JOIN HumanResources.Department D ON D.DepartmentId = EH.DepartmentId
                                        where
	                                    E.BusinessEntityId = {0}"    ;

                    cmd.CommandText = string.Format(cmd.CommandText, employeeId.ToString());
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        e.Load(reader);
                    }
                }
            }
            return(e);
        }
コード例 #3
0
ファイル: Employee.cs プロジェクト: mikechowdiv/CSharpFun
        public Employee GetEmployeeDoNotCall(int employeeId)
        {
            Employee e = new Employee();

            using (SqlConnection conn = new SqlConnection("Data Source=LAPTOP-JEM4G87I;Initial Catalog=AdventureWorks2014;Integrated Security=True"))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT * FROM HumanResources.Employee E
	JOIN Person.Person P ON E.BusinessEntityID = P.BusinessEntityID AND P.PersonType = 'EM'
	JOIN HumanResources.EmployeeDepartmentHistory EH ON E.BusinessEntityID = EH.BusinessEntityID
	JOIN HumanResources.Department D ON D.DepartmentID = EH.DepartmentID
WHERE 
	E.BusinessEntityID = {0}"    ;

                    cmd.CommandText = string.Format(cmd.CommandText, employeeId.ToString());

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        e.Load(reader);
                    }
                }
            }

            return(e);
        }
コード例 #4
0
ファイル: Employee.cs プロジェクト: mikechowdiv/CSharpFun
        public Employee GetEmployee(int employeeId)
        {
            //EXEC GetEmployeeDetails 1
            Employee e = new Employee();

            using (SqlConnection conn = new SqlConnection("Data Source=LAPTOP-JEM4G87I;Initial Catalog=AdventureWorks2014;Integrated Security=True"))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"GetEmployeeDetails";
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    SqlParameter p1 = new SqlParameter("businessEntityId", System.Data.SqlDbType.Int);
                    p1.Value = employeeId;

                    cmd.Parameters.Add(p1);

                    //cmd.CommandText = string.Format(cmd.CommandText, employeeId.ToString());

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        e.Load(reader);
                    }
                }
            }

            return(e);
        }
コード例 #5
0
ファイル: Employee.cs プロジェクト: skhandorin/AdoNet
        /// <summary>
        /// Returns an employee using Inline SQL
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        public Employee GetEmployeeDONOTCALL(int employeeId)
        {
            var e = new Employee();

            using (SqlConnection conn = DB.GetSqlConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
select * 
  from HumanResources.Employee e
    join Person.Person p on p.BusinessEntityID = e.BusinessEntityID and p.PersonType = 'EM'
	join HumanResources.EmployeeDepartmentHistory eh on eh.BusinessEntityID = e.BusinessEntityID
	join HumanResources.Department d on d.DepartmentID = eh.DepartmentID
  where e.BusinessEntityID = {0}";
                    cmd.CommandText = string.Format(cmd.CommandText, employeeId.ToString());
                    SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                    if (reader.Read())
                    {
                        e.Load(reader);
                    }
                }
            }

            return(e);
        }
コード例 #6
0
ファイル: Employee.cs プロジェクト: zhu711/adodemo
        /// <summary>
        /// Execute as inline sql statement
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        public Employee GetEmployee(int employeeId)
        {
            Employee e = new Employee();

            DataLayer.DB.ApplicationName = "WinDemo Application";
            using (SqlConnection conn = DB.GetSqlConnection())
            {
                using(SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from HumanResources.Employee E join Person.Person P on E.BusinessEntityID = P.BusinessEntityID and P.PersonType = 'EM' join HumanResources.EmployeeDepartmentHistory EH on E.BusinessEntityID = EH.BusinessEntityID join HumanResources.Department D on D.DepartmentID = Eh.DepartmentID where E.BusinessEntityID = {0}";
                    cmd.CommandText = string.Format(cmd.CommandText, employeeId.ToString());
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            e.Load(reader);
                        }
                    }
                }
            }
            return e;
        }
コード例 #7
0
ファイル: Employee.cs プロジェクト: zhu711/adodemo
        /// <summary>
        /// Execute as SP
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        public Employee GetEmployeeBySp(int employeeId)
        {
            Employee e = new Employee();

            DataLayer.DB.ApplicationName = "WinDemo Application";
            using (SqlConnection conn = DB.GetSqlConnection())
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    SqlParameter p1 = new SqlParameter("businessEntityId", System.Data.SqlDbType.Int);
                    p1.Value = employeeId;

                    cmd.CommandText = "GetEmployeeDetails";
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(p1);

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            e.Load(reader);
                        }
                    }
                }
            }
            return e;
        }