我有一个DataGridView,如下所示:
s_code | s_name | t_result | ______________________________________ S2 | John | |
我使用以下代码来显示它:
private void ViewStatus()
{
BindingSource bs1 = new BindingSource();
string val1 = label8.Text;
string val = label13.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ToString());
SqlCommand cmd = new SqlCommand("SELECT s_code, s_name, t_result FROM " + val + " WHERE t_code='" + val1 + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
//con.Open();
//cmd.ExecuteNonQuery();
//da.Fill(dt);
dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
da.Fill(dt);
bs1.DataSource = dt;
dataGridView1.DataSource = bs1;
dataGridView1.DataMember = label13.Text;
dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
我想编辑“t_result”单元格中的值,并在按下回车键后,将其发送到SQL Server表中并更新它。谢谢您的帮助。