Пример #1
0
        private void btnThemLop_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = KetNoi.str;
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;
            string TenKhoa;

            TenKhoa         = cboKhoa.SelectedItem.ToString();
            cmd.CommandText = "SELECT Khoa_ID FROM Khoa WHERE TenKhoa='" + TenKhoa + "'";
            SqlDataReader rd;

            rd = cmd.ExecuteReader();
            DataTable td = new DataTable();

            td.Load(rd);
            string MaKhoa;

            MaKhoa = td.Rows[0][0].ToString();

            cmd.CommandText = "INSERT INTO Lop VALUES('" + txtMaLop.Text + "','" + txtTenLop.Text + "','" + MaKhoa + "')";
            cmd.ExecuteNonQuery();
            DialogResult result;

            result = MessageBox.Show("THÊM DỮ LIỆU THÀNH CÔNG", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            if (result == DialogResult.OK)
            {
                this.Close();
                frmThemLop frm = new frmThemLop(Khoa_ID);
                frm.Show();
            }
        }
Пример #2
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            this.Close();
            frmThemLop frm = new frmThemLop(Khoa_ID);

            frm.Show();
        }