public ChildrenClass DetailWithParent(int id) { MysqlConnect(); string query = "select * from child join parent on parent.parent_id = child.f_parent_id where child_id = " + id; MySqlCommand comm = new MySqlCommand(query); comm.Connection = mysql; mysql.Open(); MySqlDataReader dr = comm.ExecuteReader(); dr.Read(); parentClass p = new parentClass(); ChildrenClass x = new ChildrenClass { child_id = (int)dr["child_id"], f_parent_id = (int)dr["f_parent_id"], child_name = dr["child_name"].ToString(), parent_name = dr["parent_name"].ToString(), list_parent = new SelectList(p.Read(), "parent_id", "parent_name", (int)dr["f_parent_id"]) }; mysql.Close(); return(x); }
public void Add(ChildrenClass p) { MysqlConnect(); string query = "INSERT INTO `child` (`child_id`, `child_name`, `f_parent_id`) VALUES(NULL, '" + p.child_name + "', " + p.f_parent_id + ")"; MySqlCommand comm = new MySqlCommand(query); comm.Connection = mysql; mysql.Open(); comm.ExecuteNonQuery(); mysql.Close(); return; }
public void Edit(ChildrenClass p) { MysqlConnect(); string query = "UPDATE `child` SET `child_name` = '" + p.child_name + "' WHERE `child`.`child_id` = " + p.child_id; MySqlCommand comm = new MySqlCommand(query); comm.Connection = mysql; mysql.Open(); comm.ExecuteNonQuery(); mysql.Close(); return; }
public bool isExist(ChildrenClass p) { MysqlConnect(); string query = "select * from child where child_name='" + p.child_name + "'"; MySqlCommand comm = new MySqlCommand(query); comm.Connection = mysql; mysql.Open(); MySqlDataReader dr = comm.ExecuteReader(); bool flg = dr.HasRows; mysql.Close(); if (flg) { return(true); } return(false); }