繁体   English   中英

如何使用表适配器 C# SQL 更新 DataGridView 更改?

[英]how to update an DataGridView changes with an Table Adapter C# SQL?

   public void DoUpdate()
    {
        SqlConnection con = new SqlConnection(string connection);
        con.Open();
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM table",con);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        this.dataGridView1.DataSource = dt;
        this.dataGridView1.Update();
        this.dataGridView1.Refresh();
        con.Close();
    }
}

我在我的 Stock_table 中进行更改后使用此方法,但数据网格仍然显示没有更改的旧数据,我只在重置我的程序后看到表中所做的更改

   public void DoUpdate()
    {
        SqlConnection con = new SqlConnection(string connection);
        con.Open();
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM table",con);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        this.dataGridView1.DataSource = dt;
        con.Close();
    }
}
The right way to update an datagridview 
why is this a method because if you are using another form to make the data insert in your table you only need to make a constructor with the previous form and after the insert you only call this method
Thanks for the help 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM