【发布时间】:2023-03-30 04:00:01
【问题描述】:
我是编程新手,我创建了以下按钮来搜索 dataGridView
private void btnInCollection1_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM dbo.SS1 WHERE InCollection = 1 ", con);
DataTable data = new DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
}
我想编辑 dataGridView 中的数据,然后使用另一个按钮保存更改。 你能帮我保存代码吗?
我尝试了以下代码,但它没有将数据保存回数据库。
private void btnSaveGridView_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
sS1BindingSource2.EndEdit();
sS1TableAdapter1.Update(this.sSDataSet1.SS1);
MessageBox.Show("You have been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Cursor.Current = Cursors.Default;
}
【问题讨论】:
标签: c# datagridview