【发布时间】:2016-04-01 13:55:02
【问题描述】:
我在 MainForm 中有一个 dataGridView,它在表单加载时列出所有相关数据。
当我想去编辑一行时。我选择它并按编辑,然后它会加载一个 EditForm。在这里我可以编辑数据并保存。
信息已成功编辑并保存,但dataGridView没有更新。
是否有我没有看到的 autoRefresh 属性或关闭编辑表单时刷新它的方法?
主窗体
private void EditAdminBtn_Click(object sender, EventArgs e)
{
EditAdminForm Admin = new EditAdminForm();
Admin.idTxt.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
Admin.usernameTxt.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
Admin.firstnameTxt.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
Admin.surnameTxt.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
Admin.emailTxt.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
Admin.statusCombo.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
Admin.ShowDialog();
}
public void MainForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'student_CBDataSetAdmin.Admin' table. You can move, or remove it, as needed.
this.adminTableAdapter.Fill(this.student_CBDataSetAdmin.Admin);
}
编辑表单
private void SaveBtn_Click(object sender, EventArgs e)
{
//SQL Connection and SQL for updating admin information
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
SqlDataAdapter sda3 = new SqlDataAdapter("UPDATE Admin set Admin_Username='" + this.usernameTxt.Text + "' , Admin_FName='" + this.firstnameTxt.Text + "' , Admin_SName='" + this.surnameTxt.Text + "' , Admin_Email='" + this.emailTxt.Text + "', Admin_Status='" + this.statusCombo.Text + "' WHERE Admin_ID='" + this.idTxt.Text + "'", con);
DataTable dt3 = new DataTable();
sda3.Fill(dt3);
MessageBox.Show("Information Successfully Updated!");
dt3.Clear();
this.Close();
}
THIS IS WHAT IT LOOKS LIKE, GRIDVIEW SOURCE AND BINDING AT THE BOTTOM
【问题讨论】:
标签: c# winforms datagridview