//add student
 private void btn_add_Click(object sender, EventArgs e)
 {
     if (tb_enrollment.Text == "" || tb_contact.Text == "" || tb_name.Text == "")
     {
         MessageBox.Show("All fields are mandatory");
     }
     else
     {
         if (tb_contact.TextLength > 10 || tb_contact.TextLength < 10)
         {
             MessageBox.Show("Contact no should be of 10 digits");
         }
         else
         {
             SqlDataAdapter da = new SqlDataAdapter("select * from student where enrollment_no='" + tb_enrollment.Text + "'", con);
             DataTable      dt = new DataTable();
             da.Fill(dt);
             if (dt.Rows.Count != 0)
             {
                 MessageBox.Show("Enrollment No exist in the database.Please enter unique No!");
             }
             else
             {
                 try
                 {
                     SqlCommand cmd    = new SqlCommand("Insert into student values('" + tb_studentId.Text + "','" + tb_enrollment.Text + "','" + tb_name.Text + "','" + cb_course.Text + "','" + cb_year.Text + "','" + cb_sem.Text + "','" + tb_contact.Text + "')", con);
                     int        result = cmd.ExecuteNonQuery();
                     if (result == 1)
                     {
                         MessageBox.Show("New Student Added!!");
                         tb_studentId.Text      = Increment.studentIncrement().ToString();
                         tb_enrollment.Text     = "";
                         cb_course.SelectedItem = "MCA";
                         cb_year.SelectedItem   = "1";
                         cb_sem.SelectedItem    = "1";
                         tb_contact.Text        = "";
                         tb_name.Text           = "";
                     }
                     else
                     {
                         MessageBox.Show("Something Went Wrong!!");
                     }
                 }
                 catch (SqlException ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
     }
 }
        //page load
        private void NewStudent_Load(object sender, EventArgs e)
        {
            int id = Increment.studentIncrement();

            tb_studentId.Text = id.ToString();
            menu_user.Text    = "";
            menu_user.Text    = global.user;
            tb_name.Focus();
            con = DatabaseConnection.connectDB();
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
            con.Open();
        }