3

I have DataGridView like this

s_code     |     s_name | t_result   |
______________________________________
S2         |     John   |            |

I used code below to display this

    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;

And I want to edit value in "t_result" cell, and when i hit enter, i want it sends value to table in SQL Server and update it.

Any help would be much appreciated. Thank you.

4

1 回答 1

0

使用 datagridview 单元格单击。

在该检查中查看 col t_result 是否有值,如果有,则将记录更新到 SQL Server。

于 2013-08-06T08:20:44.083 回答