PDA

View Full Version : Lưu đồng thời DataGridView và Combobox vào csdl trong C#



lnv.thinh
15-04-2011, 16:45
M định cho nhập dữ liệu trên DataGridview nhưng những thông tin giống nhau sẽ cho lấy dữ liệu từ Combobox. cột MON sẽ cho ẩn đi
bảng DIEM(MAHS,MON,D1T,D15P,D1T)

Ví dụ như hình: Mình chọn môn Toán xong nhập 1 lượt, làm sao khi chỉ chọn trên Combobox thì khi lưu cột MON cũng dc lưu vào csdl???
ảnh: http://cB6.upanh.com/21.325.28272545.6BO0/untitled.png
//code:
public string st = "Data Source=.;Initial Catalog=TEST;Integrated Security=True";
DataTable tb = new DataTable();
SqlDataAdapter ad;

private void Form1_Load(object sender, EventArgs e)
{
string sCommand = "SELECT * FROM DIEM";
SqlConnection con = new SqlConnection(st);
ad = new SqlDataAdapter(sCommand, con);
tb.Clear();
ad.Fill(tb);
dataGridView1.DataSource = tb;

string[] load1 = new string[3] { "Toan", "Ly","Hoa" };
mon.Items.AddRange(load1);

}

private void LUU_Click(object sender, EventArgs e)
{
SqlCommandBuilder s = new SqlCommandBuilder(ad);
ad.Update(tb);
MessageBox.Show("finished");
}

spiderman1989
18-04-2011, 10:11
Neu vay thì bạn lưu lại chỗ đã sửa rồi dùng câu lệnh update trong sql để lưu