【问题标题】:Passing value to table from DataGridView by editing cells itself通过编辑单元格本身将值从 DataGridView 传递到表
【发布时间】:2012-12-01 01:55:58
【问题描述】:

我有这样的 DataGridView

s_code | s_name | t_result | ______________________________________ S2 |约翰 | |

我使用下面的代码来显示这个

    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 中的表发送值并更新它。

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 有人可以帮我吗?没有这个就不能走得更远。 :(

标签: c# sql data-binding asp.net-controls


【解决方案1】:

使用 datagridview 单元格单击。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多