【发布时间】:2018-10-16 13:01:39
【问题描述】:
我真的很需要帮助。我正在制作一个学生违规系统,我需要制作一个按钮,可以删除我在我的表和链接到该表的 datagridview 中的所有记录。所以当我点击按钮时,它应该要求确认,然后当用户点击是时。该表将被截断,datagridview 中的记录将刷新。我很难过,你能帮帮我吗?谢谢。
private void button2_Click_1(object sender, EventArgs e)
{
string query = "Truncate table [transaction]";
using (SqlConnection xcon = new SqlConnection(@"Server=GLR\SQLEXPRESS;Database=SE_Project;Integrated Security=SSPI;"))
{
using (SqlCommand xcom = new SqlCommand(query, xcon))
{
SqlDataAdapter xdapter = new SqlDataAdapter(xcom);
try
{
xcon.Open();
if (this.dataGridViewAdminTransac.DataSource != null)
{
this.dataGridViewAdminTransac.DataSource = null;
MessageBox.Show("Are you sure?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
}
else
{
this.dataGridViewAdminTransac.Rows.Clear();
MessageBox.Show("Are you sure?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
}
AdminView temp = new AdminView();
temp.Show();
this.Hide();
}
catch (Exception)
{
throw;
}
finally
{
xcon.Close();
}
}
}
}
【问题讨论】:
标签: c# datagridview refresh truncate