public void create(DB_objects.Section s) { SqlCommand comm = new SqlCommand("INSERT INTO section(name, description) VALUES(@name, @description)", myConnection); comm.Parameters.Add("@name", s.name); comm.Parameters.Add("@description", s.description); }
public bool update(DB_objects.Section s) { SqlCommand comm = new SqlCommand("UPDATE section SET name=@name, description=@description WHERE section_code=@section_code", myConnection); comm.Parameters.Add("@name", s.name); comm.Parameters.Add("@description", s.description); comm.Parameters.Add("@section_code", s.section_code); return(comm.ExecuteNonQuery() == 1); }
private static void fillSections(string language, SqlConnection connection) { SqlCommand cmd = new SqlCommand("sp_connectSection", connection); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@selectedLanguage", System.Data.SqlDbType.NVarChar).Value = language; SqlDataReader reader = cmd.ExecuteReader(); DB_objects.Section s; while (reader.Read()) { s = new DB_objects.Section(reader[1].ToString(), reader[2].ToString()); s.addAttribute(reader[3].ToString(), reader[4].ToString(), reader[5].ToString()); sections[reader[0].ToString()] = s; } reader.Close(); }
public List <DB_objects.Section> retrieve() { List <DB_objects.Section> result = new List <DB_objects.Section>(); SqlCommand comm = new SqlCommand("SELECT section_code, name, description " + "FROM section ", myConnection); SqlDataReader reader = comm.ExecuteReader(); DB_objects.Section s; while (reader.Read()) { s = new DB_objects.Section(); s.section_code = Int32.Parse(reader[0].ToString()); s.name = reader[1].ToString(); s.description = reader[2].ToString(); result.Add(s); } reader.Close(); return(result); }