public List<TaskEntity> GetDontDone() { SqlConnection con = new SqlConnection(con_str); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM tbl_task WHERE IsDone = 0"; cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int id; string title; bool isDone; int priority; while (reader.Read()) { id = int.Parse( reader[0].ToString() ); title = reader[1].ToString(); isDone = Boolean.Parse( reader[2].ToString() ); priority = int.Parse(reader[3].ToString()); TaskEntity task = new TaskEntity(id, title, isDone, priority); } return listTask; }
public TaskEntity SelectById(int Id) { SqlConnection con = new SqlConnection(con_str); SqlCommand cmd = new SqlCommand(); cmd.CommandText = string.Format("SELECT * FROM tbl_task WHERE Id = {0}", Id); cmd.CommandType = CommandType.Text; cmd.Connection = con; int id = 0; string title = " "; bool isDone = false; int priority = 0; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { id = int.Parse(reader[0].ToString()); title = reader[1].ToString(); isDone = Boolean.Parse(reader[2].ToString()); priority = int.Parse( reader[3].ToString() ); } con.Close(); TaskEntity task = new TaskEntity(id, title, isDone, priority); return task; }
public List<TaskEntity> GetAll( string Id_Task ) { SqlConnection con = new SqlConnection(con_str); SqlCommand cmd = new SqlCommand(); //cmd.CommandText = "SELECT * FROM tbl_task"; cmd.CommandText = String.Format( "SELECT * FROM tbl_task WHERE Id_User = {0}", Id_Task ); cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int id; string title; bool isDone; int priority; while (reader.Read()) { id = int.Parse( reader[0].ToString() ); title = reader[1].ToString(); isDone = Boolean.Parse( reader[2].ToString() ); priority = int.Parse( reader[3].ToString() ); TaskEntity task = new TaskEntity( id , title, isDone, priority ); listTask.Add(task); } con.Close(); return listTask; }