This is my code:
String cmdText = ("UPDATE sinhvien SET Ho= '" + HoSV + "',Ten = '" + TenSV + "', Ngaysinh= '" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "',Ghichu='" + GhiChu + "',Diemthi = '" + DiemThi + "' WHERE idSinhVien =" dataGridView1.SelectedRows[0].Cells[0].Value.ToString()IDSinhVien);
MySqlCommand cmd = new MySqlCommand(cmdText, constr);
cmd.ExecuteNonQuery();

I cannot update, if i change idsinhvien = int => success. but mysql idsinhvien= varchar => error

Recommended Answers

All 4 Replies

Can you debug this and show what the SQL statement parses out to please?

unknown column 'user_id' in 'where clause'

Where did user_id come from? I don't see that in your code which builds up the sql statement.

change the dateTimePicker1.Value.ToString("yyyy/MM/dd") to dateTimePicker1.Value.ToString("yyyy-MM-dd") and "' WHERE idSinhVien =" dataGridView1.SelectedRows[0].Cells[0].Value.ToString()IDSinhVien)"
to "' WHERE idSinhVien=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() +"')"

Note: dataGridView1.SelectionMode must be FullRowSelect.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.