我尝试删除记录,但有此异常. [英] i try to delete record but there is this exception..
问题描述
你好,
我试图从数据网格和数据库中删除一条记录,我已经编写了这段代码:
i try to delete a record from a datagrid and DB,,i've written this code:
adapter.DeleteCommand = new SqlCommand("DELETE FROM tabName WHERE ID=@ID", connect);
adapter.DeleteCommand.Parameters.Add("@ID", SqlDbType.Int, 0).Value = stdDataGrid.SelectedItem;
connect.Open();
adapter.DeleteCommand.ExecuteNonQuery();
MessageBox.Show("Row deleted !! ");
adapter.Update(ds, "tabName");
adapter.Fill(ds);
connect.Close();
这个异常在我看来:
参数化查询'(@ID int)DELETE FROM&tabName WHERE ID = @ ID'需要未提供的参数'@ID'
The parameterized query '(@ID int)DELETE FROM tabName WHERE ID=@ID' expects the parameter '@ID', which was not supplied
plz告诉我该怎么办..
plz tell me what should i do..??
推荐答案
aseel,
我能够复制您遇到的异常.导致该异常的原因是"stdDataGrid.SelectedItem为null".
I was able to replicate the exception that ur getting. The cause of the exception is "stdDataGrid.SelectedItem is null".
由于此错误而导致的.我建议您在执行删除命令之前,先检查stdDataGrid.SelectedItem中的值是否为null.
As a result of this ur getting this error. I would suggest u to check that value in stdDataGrid.SelectedItem is not null before executing the delete command.
如果可以解决您的查询,请将其标记为答案.
Please mark it as an answer if it resolves ur query.
这篇关于我尝试删除记录,但有此异常.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!