private void btnDelete_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; cmd1 = new SqlCommand("select rollno from student where rollno='" + txtDelete.Text + "'", con); SqlDataReader dr = cmd1.ExecuteReader(); if (dr.Read()) { dr.Close(); cmd1 = new SqlCommand("delete from takes where rollno='" + txtDelete.Text + "'", con); cmd1.ExecuteNonQuery(); cmd1 = new SqlCommand("delete from student where rollno='" + txtDelete.Text + "'", con); cmd1.ExecuteNonQuery(); LoadData(); MessageBox.Show($"{txtDelete.Text} has been deleted succesfully..."); } else { MessageBox.Show("Please enter a valid roll number.."); } con.Close(); }
private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd = new SqlCommand("insert into auth (Username, Password) values('" + txtUsername.Text + "', '" + txtPassword.Text + "')", con); if (txtUsername.Text != "" || txtPassword.Text != "") { try { cmd.ExecuteNonQuery(); MessageBox.Show($"Registration successful\nUsername : {txtUsername.Text}\nPassword : {txtPassword.Text}"); } catch (Exception er) { MessageBox.Show(er.Message); } finally { con.Close(); } } else { MessageBox.Show("Username/Password cannot be empty"); } txtUsername.Text = ""; txtPassword.Text = ""; }
private void LoadAddCourse() { DataTable dt = new DataTable(); dt.Columns.Add("Sl. no."); dt.Columns.Add("Roll no."); dt.Columns.Add("Course code"); SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from takes", con); SqlDataReader dr = cmd.ExecuteReader(); int slno = 1; while (dr.Read()) { DataRow drx = dt.NewRow(); drx["Sl. no."] = slno++; drx["Roll no."] = dr["rollno"].ToString(); drx["Course code"] = dr["ccode"].ToString(); dt.Rows.Add(drx); } grdstudentCourse.DataSource = dt; con.Close(); }
private void LoadCourseList() { DataTable dt = new DataTable(); dt.Columns.Add("Sl. no."); dt.Columns.Add("Course name"); dt.Columns.Add("Course code"); dt.Columns.Add("Credit"); dt.Columns.Add("Dept. no."); SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from course", con); SqlDataReader dr = cmd.ExecuteReader(); int slno = 1; while (dr.Read()) { DataRow drx = dt.NewRow(); drx["Sl. no."] = slno++; drx["Course name"] = dr["cname"].ToString(); drx["Course code"] = dr["ccode"].ToString(); drx["Credit"] = dr["credit"].ToString(); drx["Dept. no."] = dr["dno"].ToString(); dt.Rows.Add(drx); } grdcourseList.DataSource = dt; con.Close(); }
private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; if (btnAddStudent.Text == "ADD STUDENT") { try { cmd1 = new SqlCommand("insert into student (fname, lname, rollno, email, gender, dob, hobby, vill, pin, hname, dno, semno, cgpa, rmno)" + "values('" + txtFname.Text + "', '" + txtLname.Text + "', '" + txtRollno.Text + "', '" + txtEmail.Text + "', '" + txtGender.Text + "', '" + txtDob.Text + "','" + txtHobby.Text + "'," + " '" + txtVill.Text + "', " + txtPin.Text + ", '" + txtHname.Text + "', " + txtDno.Text + ", " + txtSno.Text + ", " + txtCgpa.Text + ", " + txtRmno.Text + ")", con); cmd1.ExecuteNonQuery(); LoadData(); MessageBox.Show($"{txtRollno.Text} added successfully"); ClearFields(); } catch (Exception er) { MessageBox.Show(UsefullStrings.ErrorString() + er.Message); } finally { con.Close(); } } else { try { cmd1 = new SqlCommand("update student set fname='" + txtFname.Text + "', lname='" + txtLname.Text + "', email='" + txtEmail.Text + "'," + "gender='" + txtGender.Text + "', dob='" + txtDob.Text + "', hobby='" + txtHobby.Text + "', vill='" + txtVill.Text + "', pin=" + txtPin.Text + "," + "hname='" + txtHname.Text + "', dno=" + txtDno.Text + ", semno=" + txtSno.Text + ", cgpa=" + txtCgpa.Text + ", rmno=" + txtRmno.Text + " where rollno='" + txtRollno.Text + "'", con); cmd1.ExecuteNonQuery(); btnAddStudent.Text = "ADD STUDENT"; LoadData(); MessageBox.Show($"Information of {txtRollno.Text} updated successfully"); ClearFields(); } catch (Exception er) { MessageBox.Show(UsefullStrings.ErrorString() + er.Message); } finally { con.Close(); } } }
private void btnSearch_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; try { cmd1 = new SqlCommand("select * from student where rollno='" + txtSearch.Text + "'", con); SqlDataReader dr = cmd1.ExecuteReader(); dr.Read(); txtFname.Text = dr["fname"].ToString(); txtLname.Text = dr["lname"].ToString(); txtRollno.Text = dr["rollno"].ToString(); txtEmail.Text = dr["email"].ToString(); txtGender.Text = dr["gender"].ToString(); txtDob.Text = dr["dob"].ToString(); txtHobby.Text = dr["hobby"].ToString(); txtVill.Text = dr["vill"].ToString(); txtPin.Text = dr["pin"].ToString(); txtHname.Text = dr["hname"].ToString(); txtDno.Text = dr["dno"].ToString(); txtSno.Text = dr["semno"].ToString(); txtCgpa.Text = dr["cgpa"].ToString(); txtRmno.Text = dr["rmno"].ToString(); string course = "Courses taken by " + txtRollno.Text + " :\n"; int cnt = 1; dr.Close(); cmd1 = new SqlCommand("select ccode from takes where rollno='" + txtRollno.Text + "'", con); dr = cmd1.ExecuteReader(); while (dr.Read()) { course += ("" + cnt + " : " + dr[0].ToString() + "\n"); cnt++; } course += "\nClick OK to see other details..."; MessageBox.Show(course); btnAddStudent.Text = "UPDATE"; } catch (Exception) { MessageBox.Show("Please enter a valid roll number.."); } finally { con.Close(); } }
private void btnAddClist_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; if (btnAddClist.Text == "ADD") { try { cmd1 = new SqlCommand("insert into course values('" + txtCname.Text + "', '" + txtCcodeCL.Text + "'," + " " + txtCredit.Text + ", " + txtDnoCl.Text + ")", con); cmd1.ExecuteNonQuery(); CourseListClr(); LoadCourseList(); } catch (Exception er) { MessageBox.Show(UsefullStrings.ErrorString() + er.Message); } finally { con.Close(); } } else { try { cmd1 = new SqlCommand("update course set cname='" + txtCname.Text + "', credit=" + txtCredit.Text + "," + "dno=" + txtDnoCl.Text + " where ccode='" + txtCcodeCL.Text + "'", con); cmd1.ExecuteNonQuery(); //MessageBox.Show("updated"); CourseListClr(); btnAddClist.Text = "ADD"; LoadCourseList(); } catch (Exception er) { MessageBox.Show(er.Message); } finally { con.Close(); } } }
private void LoadData() { DataTable dt = new DataTable(); dt.Columns.Add("Sl. no."); dt.Columns.Add("First name"); dt.Columns.Add("Last name"); dt.Columns.Add("Roll no."); dt.Columns.Add("Email"); dt.Columns.Add("Gender"); dt.Columns.Add("DOB"); dt.Columns.Add("Village"); dt.Columns.Add("PIN"); dt.Columns.Add("Hostel"); dt.Columns.Add("Room no."); dt.Columns.Add("Dept. no."); dt.Columns.Add("Sem. no."); dt.Columns.Add("CGPA"); dt.Columns.Add("Hobby"); SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from student", con); SqlDataReader dr = cmd.ExecuteReader(); int slno = 1; while (dr.Read()) { DataRow drx = dt.NewRow(); drx["Sl. no."] = slno++; drx["First name"] = dr["fname"].ToString(); drx["Last name"] = dr["lname"].ToString(); drx["Roll no."] = dr["rollno"].ToString(); drx["Email"] = dr["email"].ToString(); drx["Gender"] = dr["gender"].ToString(); drx["DOB"] = dr["dob"].ToString(); drx["Village"] = dr["vill"].ToString(); drx["PIN"] = dr["pin"].ToString(); drx["Hostel"] = dr["hname"].ToString(); drx["Room no."] = dr["rmno"].ToString(); drx["Dept. no."] = dr["dno"].ToString(); drx["Sem. no."] = dr["semno"].ToString(); drx["CGPA"] = dr["cgpa"].ToString(); drx["Hobby"] = dr["hobby"].ToString(); dt.Rows.Add(drx); } dataGridView1.DataSource = dt; }
private void btnAddDlist_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; if (btnAddDlist.Text == "ADD") { try { cmd1 = new SqlCommand("insert into department values('" + txtDname.Text + "', " + txtDnoDl.Text + ")", con); cmd1.ExecuteNonQuery(); DeptListClr(); LoadDeptList(); } catch (Exception er) { MessageBox.Show(UsefullStrings.ErrorString() + er.Message); } finally { con.Close(); } } else { try { cmd1 = new SqlCommand("update department set dname='" + txtDname.Text + "' where dno=" + txtDnoDl.Text + "", con); cmd1.ExecuteNonQuery(); DeptListClr(); btnAddDlist.Text = "ADD"; LoadDeptList(); } catch (Exception er) { MessageBox.Show(er.Message); } finally { con.Close(); } } }
private void btnAddStudent_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd1; if (btnAddCourse.Text == "ADD") { try { cmd1 = new SqlCommand("insert into takes values('" + txtRollno.Text + "', '" + txtCcodeAc.Text + "')", con); cmd1.ExecuteNonQuery(); txtCcodeAc.Text = ""; LoadAddCourse(); } catch (Exception er) { MessageBox.Show(UsefullStrings.ErrorString() + er.Message); } finally { con.Close(); } } else { try { cmd1 = new SqlCommand("delete from takes where rollno='" + txtRollno.Text + "' and ccode='" + txtCcodeAc.Text + "'", con); cmd1.ExecuteNonQuery(); LoadAddCourse(); AddCourseClr(); btnAddCourse.Text = "ADD"; } catch (Exception er) { MessageBox.Show(er.Message); } finally { con.Close(); } } }
private void button1_Click(object sender, EventArgs e) { if (txtUsername.Text != "" || txtPassword.Text != "") { SqlConnection con = new SqlConnection(UsefullStrings.GetString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from auth where Username='******' and Password='******'", con); try { SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { Form1 f = new Form1(); f.ShowDialog(); } else { MessageBox.Show("Wrong Username/Password"); } } catch (Exception er) { MessageBox.Show(er.Message); } finally { con.Close(); } } else { MessageBox.Show("Username/Password cannot be empty"); } txtUsername.Text = ""; txtPassword.Text = ""; }