//Loading subject name into the combo box void SubjectCombo() { SqlConnection conn = new SqlConnection(myconnstring); //Connect to DB string sql = "select * from Subject_Table"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader SubjectRead; try { conn.Open(); SubjectRead = cmd.ExecuteReader(); while (SubjectRead.Read()) { string SubjectName = SubjectRead["SubjectName"].ToString(); string SubjectCode = SubjectRead["SubjectCode"].ToString(); cmdSubjectMS.Items.Add(SubjectName + " ( " + SubjectCode + " ) "); } } catch (Exception ex) { } finally { conn.Close(); } }
private void listOfConsecutive_Load(object sender, EventArgs e) { string sql = "select * from Subject_Table"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader SubjectRead; try { if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); SubjectRead = cmd.ExecuteReader(); while (SubjectRead.Read()) { string SubjectName = SubjectRead["SubjectName"].ToString(); string SubjectCode = SubjectRead["SubjectCode"].ToString(); List.Items.Add(SubjectName + " ( " + SubjectCode + " ) "); } } catch (Exception ee) { MessageBox.Show("Error while data binding "); } //dataGridView.Columns[1].HeaderText = "Tag Codes"; //dataGridView.Columns[2].HeaderText = "Subject Code"; }
void loadSubject() { string sql = "SELECT * FROM Subject_Table"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader SubjectRead; try { conn.Open(); SubjectRead = cmd.ExecuteReader(); while (SubjectRead.Read()) { string SubjectName = SubjectRead["SubjectName"].ToString(); string SubjectCode = SubjectRead["SubjectCode"].ToString(); subject_cmb.Items.Add(SubjectName + " - " + SubjectCode); } } catch (Exception) { } finally { conn.Close(); } }