示例#1
0
        private void button3_Click(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("update [students] set Roll = " + textRoll.Text + ",Name = '" + textName.Text + "',fk_class_id = (select [class_id] from [class] where class_name = '" + comboClass.Text + "'),father = '" + textFather.Text + "',mother = '" + textMother.Text + "',contact =" + textContact.Text + ",gender = '" + RadioValue + "',dob='" + dateDob.Value.Date.ToString("yyyyMMdd") + "',admissionDate= '" + dateAdmit.Value.Date.ToString("yyyyMMdd") + "',address = '" + textAddress.Text + "',photo ='" + imgurl + "' where st_id = " + stID + "", conn);

            try
            {
                int result = cmd.ExecuteNonQuery();
                if (result > 0)
                {
                    MessageBox.Show("Update Success!!!", "Succesfull");
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error"); }
            conn.Close();
            h.RefreshStudentTable();
        }
示例#2
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            conn.Open();
            string     query = "INSERT INTO [students] (Roll,Name,fk_class_id,father,mother,contact,gender,dob,admissionDate,address,photo) VALUES(" + textRoll.Text + ",'" + textName.Text + "',(select [class_id] from [class] where class_name = '" + comboClass.Text + "'),'" + textFather.Text + "','" + textMother.Text + "'," + textContact.Text + ",'" + RadioValue + "','" + dateDob.Value.Date.ToString("yyyyMMdd") + "','" + dateAdmit.Value.Date.ToString("yyyyMMdd") + "','" + textAddress.Text + "','" + imgurl + "')";
            SqlCommand cmd   = new SqlCommand(query, conn);

            try
            {
                int result = cmd.ExecuteNonQuery();
                if (result > 0)
                {
                    MessageBox.Show("Successfully added!!!", "Succesfull");
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error"); }
            h.RefreshStudentTable();
            conn.Close();
        }