【发布时间】:2016-04-03 11:44:17
【问题描述】:
我正在尝试从链接到数据库中的表的 DataGridView 中删除选定的行。它说明了以下错误代码。
关于我在哪里出错的任何想法?
删除按钮代码
private void DeleteExtraBtn_Click(object sender, EventArgs e)
{
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");
con.Open();
try
{
//Delete selected extra row
SqlCommand sda = new SqlCommand("Delete From Extra Where Extra_ID = @Extra_ID", con);
sda.Parameters.AddWithValue("@ExtraID", extraGridView.CurrentRow.Cells[0]);
sda.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
loadExtraTable();
}
【问题讨论】:
标签: c# mysql datagridview