使用sqldataadapter从datagridview中删除数据

时间:2014-01-29 11:33:32

标签: c# sql-server

我在sql server中有数据的datagridview,我想用dataadapter删除所选的行这是我的代码

DialogResult dr;

dr = MessageBox.Show("Are you sure you want to delete this User?", "Delete User", MessageBoxButtons.YesNo);

if (dr == DialogResult.Yes)
{
    da.DeleteCommand = new SqlCommand("DELETE FROM tb_Accounts WHERE AccountID=@AccountID", conn);
    da.DeleteCommand.Parameters.Add("@AccountID",SqlDbType.Int).Value = ds.Tables[0].Rows;


    conn.Open();
    da.DeleteCommand.ExecuteNonQuery();
    conn.Close();
}

我的错误是找不到表0,我不知道那是什么..

0 个答案:

没有答案