资 源 简 介
C#更新修改DataGridView数据,请直接在DataGridView表格中修改数据,C# 更新DataGridView数据的实现代码如下:
private void button1_Click(object sender, EventArgs e)
{//更新数据
var MyCount = this.sqlDataAdapter1.Update(this.dataSet1, "Customers");
var MyInfo = "成功更新" + MyCount.ToString() + "条记录!";
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);
}
private void Form1_Load(object sender, EventArgs e)
{//读取Customers数据表记录
var MySQL = "Select * From Customers ";
this.sqlConnection1.ConnectionString = "Data Source=.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand("Select * From Employees", this.sqlConnection1);
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(this.sqlCommand1);
this.sqlCommandBuilder1 = new System.Data.SqlClient.SqlCommandBuilder(this.sqlDataAdapter1);
this.sqlDataAdapter1.Fill(this.dataSet1, "Customers");
this.dataGridView1.DataSource = this.dataSet1.Tables[0];