【发布时间】:2017-02-20 05:29:36
【问题描述】:
我已经为这个特定问题寻找答案太久了,但我没有得到明确的帮助。
你能帮我刷新数据网格视图吗?当我单击插入按钮时,我必须重新启动程序才能查看最近更新的数据。 我试过使用 datagridview.refresh(); 和 datagridview.update();在 datagridview 和插入按钮代码中,但它不会工作。这是我在数据库中插入数据的代码:
private void btnSave_Click(object sender, EventArgs e)
{
DatabaseConnection dbcon = new DatabaseConnection();
dbcon.OpenDbConnection();
dbcon.commandConnection();
gender1();
string query = "Insert into Employee_personal_info (Last_Name,Middle_Name,First_Name,Phone_Number,Email_Address,Permanent_Address,Temporary_Address,Gender,userimage) values ('" + textBoxLastName.Text + "','" + textBoxMiddleName.Text + "', '" + textBoxFirstName.Text + "','" + textBoxPhoneNumber.Text + "','" + textBoxEmailAddress.Text + "','" + textBoxPermanentAdd.Text + "','" + textBoxTemporaryAdd.Text + "','" + gender1() + "','"+textBox_imagepath.Text+"') ";
string query2 = "Select @@Identity";
int ID;
try
{
dbcon.commandExecuteNonQuery(query);
ID = (int)dbcon.commandExecuteScalar(query2);
string query1 = " Insert into Employee_company_info (E_ID,Department, Post, Duty_shift, Date_Hired, Date_Released) values ("+ID+",'" + comboBoxDepartment.Text + "','" + comboBoxPost.Text + "','" + comboBoxDutyShift.Text + "','" + dateTimePicker1.Value + "','" + dateTimePicker2.Value + "') ";
dbcon.commandExecuteNonQuery(query1);
MessageBox.Show("data inserted sucessfully");
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
MessageBox.Show("data not inserted ");
}
}
提前致谢。
【问题讨论】:
-
当您加载数据并将其附加到数据网格中时,您的代码在哪里?
标签: datagridview refresh