// select All public static List <emp> selectAll() { string query = "select * from Employee1;"; List <emp> emps = new List <emp>(); Connect.Open(); SqlCommand cmd = new SqlCommand(query, Connect); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string Empid = reader["Emp_ID"].ToString(); int Empid2 = Convert.ToInt32(Empid); emp us = new emp(); us.Empid = Empid2; us.EmpName = reader["Emp_Name"].ToString(); us.EmpSalary = reader["Emp_Salary"].ToString(); us.UserId = Convert.ToInt32(reader["User_ID"]); us.Sdate = reader["Start_Date"].ToString(); emps.Add(us); } Connect.Close(); return(emps); }
// update public static void update(emp emps) { string query = "UPDATE Employee1 set Emp_Name=@pn,Emp_Salary=@s,Start_Date=@pass where Emp_ID=@id"; SqlCommand cmd = new SqlCommand(query, Connect); Connect.Open(); cmd.Parameters.AddWithValue("@id", emps.Empid); cmd.Parameters.AddWithValue("@pn", emps.EmpName); cmd.Parameters.AddWithValue("@s", emps.EmpSalary); cmd.Parameters.AddWithValue("@pass", emps.Sdate); cmd.ExecuteNonQuery(); Connect.Close(); }
// add new emp. public static void addTo(emp em) { string query = "insert into Employee1 values(@Emp_Name,@Emp_Salary,@Start_Date,@roleID,@userID)"; Connect.Open(); SqlCommand cmd = new SqlCommand(query, Connect); cmd.Parameters.AddWithValue("@userID", em.UserId); cmd.Parameters.AddWithValue("@Emp_Name", em.EmpName); cmd.Parameters.AddWithValue("@Emp_Salary", em.EmpSalary.ToString()); cmd.Parameters.AddWithValue("@roleID", em.roleID); cmd.Parameters.AddWithValue("@Start_Date", em.Sdate); cmd.ExecuteNonQuery(); Connect.Close(); }