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.

Ojen
  • 817
  • 12
  • 23

1 Answers1

0

Use a datagridview cell click.

Within that check to see if the col t_result has a value, if so update records into SQL Server.