public sec Getsec(int id) { sec se = new sec(); SqlConnection con = new SqlConnection(constr); string sql = "Select * from section Where id=" + id; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = sql; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { //Students std = new Students(); se.Id = Int32.Parse(reader["id"].ToString()); se.Name = reader["section_name"].ToString(); } } cmd.Connection.Close(); return(se); }
public int Update(sec se, int id) { var result = 0; SqlConnection con = new SqlConnection(constr); string sql = string.Format("Update section set section_name='{0}' where id=" + id + "", se.Name); SqlCommand cmd = new SqlCommand(sql, con); con.Open(); result = cmd.ExecuteNonQuery(); con.Close(); return(result); }
public int Insert(sec se) { var result = 0; con = new SqlConnection(constr); string sql = string.Format("Insert into section(section_name)values('{0}')", se.Name); cmd = new SqlCommand(sql, con); con.Open(); result = cmd.ExecuteNonQuery(); con.Close(); return(result); }
protected void Button1_Click(object sender, EventArgs e) { sec d = new sec(); d.Name = TextBox1.Text; if (new sceAccess().Insert(d) > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Succesfully Saved')", true); this.GridView1.DataSourceID = SqlDataSource1.ID; } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Saved Fail')", true); } }
protected void Button2_Click(object sender, EventArgs e) { int id = Int32.Parse(HiddenField1.Value); sec se = new sec(); se.Name = TextBox1.Text; sceAccess manager = new sceAccess(); if (manager.Update(se, id) > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Succesfully updated')", true); this.GridView1.DataSourceID = SqlDataSource1.ID; } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Succesfully updated')", true); } }
public List <sec> Display() { List <sec> lst = new List <sec>(); con = new SqlConnection(constr); string sql = string.Format("select * from section order by section_name asc"); cmd = new SqlCommand(sql, con); con.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { sec d = new sec(); d.Name = reader["section_name"].ToString(); d.Id = Int32.Parse(reader["id"].ToString()); lst.Add(d); } } con.Close(); return(lst); }
public static void search_files_in_folder(object obj) { string file_dir = obj.ToString(); sec this_form = (sec)obj; file_dir = this_form.file_string_dir; if (file_dir != null && file_dir.Length > 0) { if (Directory.Exists(file_dir)) { quire_name.Clear(); List <string> all_files = new List <string>(); List <string> folders = new List <string>(); folders.Add(file_dir); for (int i = 0; i < folders.Count; i++) { try { string cur_folder = folders[i]; string[] files = Directory.GetFiles(cur_folder); string[] dirs = Directory.GetDirectories(cur_folder); foreach (string item in files) { all_files.Add(item); } foreach (string item in dirs) { folders.Add(item); } } catch { } } quire_name = all_files; this_form.quire_entire(this_form); } } }