public BindingList <GlobalClass.subjectMapper> SelectSubjectClr() { string query = @"SELECT a.ID, a.Name, a.Description FROM subject as a"; BindingList <GlobalClass.subjectMapper> tempSubjectList = new BindingList <GlobalClass.subjectMapper>(); if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, dbConnect); MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int I = (int)((long)dataReader["ID"]); string N = (string)dataReader["Name"]; string D = (string)dataReader["Description"]; GlobalClass.subjectMapper tempSubject = new GlobalClass.subjectMapper(I, N, D); tempSubjectList.Add(tempSubject); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return(tempSubjectList); } else { return(tempSubjectList); } }
private void SaveBtn_Click(object sender, EventArgs e) { AlteringSubject = new GlobalClass.subjectMapper(); AlteringSubject.Name = this.subjName.Text; AlteringSubject.Description = this.subjDescription.Text; elementBase.InsertSubject(AlteringSubject); this.Close(); }
public void InsertSubject(GlobalClass.subjectMapper InsertingSubject) { if (this.openConnection() == true) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = dbConnect; string query = @"INSERT INTO subject (`Name`,`Description`) VALUES ('" + InsertingSubject.Name + "','" + InsertingSubject.Description + "')"; cmd.CommandText = query; cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } }