我已经删除了选定的数据网格,但是在调试之后,我点击了删除,但没有任何更新。*对不起我糟糕的英语。
这是我的脚本:
//Delete data buku private void DeleteDataBuku()
{
String con = (@"Data Source=FAJRI-PC\SQLEXPRESS;Initial Catalog=dbPerpustakaan;Integrated Security=True");
for (int i = 0; i < dvgPerpustakaan.Rows.Count; i++)
{
DataGridViewRow dr = dvgPerpustakaan.Rows[i];
if (dr.Selected == true)
{
dvgPerpustakaan.Rows.RemoveAt(i);
try
{
SqlConnection db = new SqlConnection(con);
db.Open();
SqlCommand dbcmd = db.CreateCommand();
string sql = "delete from Perpustakaan where KodeBuku=" + i;
dbcmd.CommandText = sql;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql, con);
DataSet myDataset = new DataSet();
SqlAdapter.Fill(myDataset);
db.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error");
}
}
}
}