private void cmbBoTuSua_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(TenChuoi.ketNoi); conn.Open(); //Truy vấn lấy chú thích string query = @"select btv.GhiChu from BoTuVung btv where btv.TenBoTuVung = N'" + cmbBoTuSua.Text + "'"; SqlCommand cmd = new SqlCommand(query, conn); txtTenBoMoi.Text = cmbBoTuSua.SelectedItem.ToString(); txtMoTaMoi.Text = XuLyDuLieu.ChuyenQuaGiaoDien(cmd.ExecuteScalar().ToString()); }
void LoadBoTu() { try { lvDanhSachBoTu.Items.Clear(); cmbTenBo.Items.Clear(); conn = new SqlConnection(TenChuoi.ketNoi); conn.Open(); string query = @"select btv.TenBoTuVung, btv.GhiChu from BoTuVung btv where btv.TenBoTuVung != N'admin'"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader read = cmd.ExecuteReader(); //Tên những bộ từ vựng while (read.Read()) { ListViewItem item = new ListViewItem(read["TenBoTuVung"].ToString()); item.SubItems.Add(XuLyDuLieu.ChuyenQuaGiaoDien(read["GhiChu"].ToString())); //item.ImageList.Images = imgAnh.Images[0]; lvDanhSachBoTu.Items.Add(item); lvDanhSachBoTu.Items[lvDanhSachBoTu.Items.Count - 1].ImageIndex = 0; cmbTenBo.Items.Add(read["TenBoTuVung"].ToString()); } btv = new BoTuVung(); } catch (SqlException) { MessageBox.Show("Kết nối thất bại", "Lỗi kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } }