private void button1_Click(object sender, EventArgs e) { int IRTBLines = 0, i = 0, j = 0; // Counter Represent Lines from TextBox //Read Lines from TextBox for (IRTBLines = 0; IRTBLines < textBox1.Lines.Length; IRTBLines++) { //If IRTBLine is not Null Then if (string.Compare(textBox1.Lines[IRTBLines], "") != 0) { //Data Base Command 2 SqlCommand DBcom2 = new SqlCommand("select * from subject where sub_name ='" + textBox1.Lines[IRTBLines] + "'", con); //Database Reader 2 SqlDataReader DBRead2; //Read From Database DBRead2 = DBcom2.ExecuteReader(); // Check if Department Name is Exist if (DBRead2.HasRows) { j = 1; //Department Name is Already Exist MessageBox.Show("subject Name =" + textBox1.Lines[IRTBLines] + " is skipped because it is already exist"); //Dispose Database command 2 and reader 2 DBRead2.Dispose(); DBcom2.Dispose(); } else { i = 1; //Department Name is Not Already Exist //Database Command3 String string SCom1 = "insert into subject values('" + textBox1.Lines[IRTBLines].ToString() + "')"; //Dispose Databse command 2 and reader 2 DBRead2.Dispose(); DBcom2.Dispose(); //Database Command 3 SqlCommand DBcom3 = new SqlCommand(SCom1, con); //Execute Database Command 3. DBcom3.ExecuteNonQuery(); //Dispose Database Command 3 DBcom3.Dispose(); //MessageBox.Show("subject Name =" + textBox1.Lines[IRTBLines] + " is entered into database"); } } } if (i == 0) { MessageBox.Show("Please input subject in text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (i == 1) { MessageBox.Show("Data Entered Into Database"); } //Clear RichTextBox1 Content textBox1.ResetText(); }
private void button1_Click_1(object sender, EventArgs e) { if (comboBox1.SelectedIndex > 0) { string cb = ""; int i = 0, j = 0; var row = (DataRowView)comboBox1.SelectedItem; //cb = comboBox1.Items[comboBox1.SelectedIndex].ToString(); cb = row["sub_name"].ToString(); int IRTBLines = 0; // Counter Represent Lines from RichTextBox //Read Lines from RichTextBox for (IRTBLines = 0; IRTBLines < textBox1.Lines.Length; IRTBLines++) { //If IRTBLine is not Null Then if (string.Compare(textBox1.Lines[IRTBLines], "") != 0) { //Data Base Command 2 SqlCommand DBcom2 = new SqlCommand("select * from student where subject = '" + cb + "' AND student_name ='" + textBox1.Lines[IRTBLines] + "'", con); //Database Reader 2 SqlDataReader DBRead2; //Read From Database DBRead2 = DBcom2.ExecuteReader(); // Check if Department Name is Exist if (DBRead2.HasRows) { i = 1; //Department Name is Not Already Exist //Database Command3 String string SCom1 = "delete from student where subject ='" + cb + "' and student_name = '" + textBox1.Lines[IRTBLines].ToString() + "'"; //Dispose Databse command 2 and reader 2 DBRead2.Dispose(); DBcom2.Dispose(); //Database Command 3 SqlCommand DBcom3 = new SqlCommand(SCom1, con); //Execute Database Command 3. DBcom3.ExecuteNonQuery(); //Dispose Database Command 3 DBcom3.Dispose(); } else { j = 1; //Department Name is Already Exist MessageBox.Show("student Name =" + textBox1.Lines[IRTBLines] + " is skipped because it doesn't exist"); //Dispose Database command 2 and reader 2 DBRead2.Dispose(); DBcom2.Dispose(); } // MessageBox.Show("Data Entered Into Database"); } } if (i == 0 && j == 0) { MessageBox.Show("Please input name in text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (i == 1) { MessageBox.Show("Student Name Deleted From Subject = " + cb + " "); } //Clear RichTextBox1 Content textBox1.ResetText(); label5.Text = "0"; } else { MessageBox.Show("Please Select Subject", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void button2_Click(object sender, System.EventArgs e) { if (comboBox1.SelectedIndex > 0) { string cb = ""; var row = (DataRowView)comboBox1.SelectedItem; //cb = comboBox1.Items[comboBox1.SelectedIndex].ToString(); cb = row["sub_name"].ToString(); int IRTBLines = 0; // Counter Represent Lines from RichTextBox //Read Lines from RichTextBox for (IRTBLines = 0; IRTBLines < textBox1.Lines.Length; IRTBLines++) { //If IRTBLine is not Null Then if (string.Compare(textBox1.Lines[IRTBLines], "") != 0) { //Data Base Command 2 SqlCommand DBcom2 = new SqlCommand("select * from student where subject = '" + cb + "' AND student_name ='" + textBox1.Lines[IRTBLines] + "'", con); //Database Reader 2 SqlDataReader DBRead2; //Read From Database DBRead2 = DBcom2.ExecuteReader(); // Check if Department Name is Exist if (DBRead2.HasRows) { //string SCom1 = "insert into student(subject,student_name,attendence) values('" + cb + "','" + textBox1.Lines[IRTBLines].ToString() + "','" + a + "')"; //Dispose Databse command 2 and reader 2 string SCom1 = "update student set attendence = attendence +1 where subject = '" + cb + "' AND student_name ='" + textBox1.Lines[IRTBLines] + "'"; DBRead2.Dispose(); DBcom2.Dispose(); //Database Command 3 SqlCommand DBcom3 = new SqlCommand(SCom1, con); //Execute Database Command 3. DBcom3.ExecuteNonQuery(); //Dispose Database Command 3 DBcom3.Dispose(); } else { //Department Name is Already Exist MessageBox.Show("student Name =" + textBox1.Lines[IRTBLines] + " These Student name not found in database (please add these student)"); //Dispose Database command 2 and reader 2 DBRead2.Dispose(); DBcom2.Dispose(); } } } //Clear RichTextBox1 Content textBox1.ResetText(); } else { MessageBox.Show("Please Select Subject", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }