コード例 #1
0
        //To View all employees details
        public IEnumerable <EmployeeDataModel> GetAllEmployees()
        {
            List <EmployeeDataModel> lstemployee = new List <EmployeeDataModel>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("spGetAllEmployees", con);
                cmd.CommandType = CommandType.StoredProcedure; con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    EmployeeDataModel employee = new EmployeeDataModel();
                    //employee.EmployeelD = Convert.ToInt32(rdr["EmployeeID"]);
                    employee.FirstName = rdr["FirstName"].ToString();
                    employee.LastName  = rdr["LastName"].ToString();
                    employee.Gender    = rdr["Gender"].ToString();
                    employee.HiredDate = rdr["HiredDate"].ToString();
                    employee.Salary    = rdr["Salary"].ToString();

                    lstemployee.Add(employee);
                }
                con.Close();
            }
            return(lstemployee);
        }
コード例 #2
0
 //To Update the records of a particluar employee
 public void UpdateEmployee(EmployeeDataModel employee)
 {
     using (SqlConnection con = new SqlConnection(connectionString))
     {
         SqlCommand cmd = new SqlCommand("spUpdateEmployee", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@EmployeelD", employee.EmployeelD);
         cmd.Parameters.AddWithValue("@FirstName", employee.FirstName);
         cmd.Parameters.AddWithValue("@LastName ", employee.LastName);
         cmd.Parameters.AddWithValue("@Gender", employee.Gender);
         cmd.Parameters.AddWithValue("@HiredDate ", employee.HiredDate);
         cmd.Parameters.AddWithValue("@Salary ", employee.Salary);
         con.Open();
         cmd.ExecuteNonQuery(); con.Close();
     }
 }
コード例 #3
0
        //Get the details of a particular employee
        public EmployeeDataModel GetEmployeeData(int?EmployeelD)
        {
            EmployeeDataModel employee = new EmployeeDataModel();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     sqlQuery = "SELECT * FROM Employee WHERE EmployeelD= " + EmployeelD;
                SqlCommand cmd      = new SqlCommand(sqlQuery, con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    employee.EmployeelD = Convert.ToInt32(rdr["EmployeelD"]);
                    employee.FirstName  = rdr["FirstName"].ToString();
                    employee.LastName   = rdr["LastName"].ToString();
                    employee.Gender     = rdr["Gender"].ToString();
                    employee.HiredDate  = rdr["HiredDate"].ToString();
                    employee.Salary     = rdr["Salary"].ToString();
                }
            }

            return(employee);
        }