通过编辑单元格将值传递给表格的DataGridView。

3

我有一个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表中并更新它。谢谢您的帮助。

1
有人可以帮我吗?没有这个,我无法继续了。:( - TheCatalySt
1个回答

0
使用DataGridView单元格单击事件。在其中检查列t_result是否有值,如果有,则更新记录到SQL Server中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接