删除提交整行错误序列不包含任何元素 [英] delete on submit an entire row error Sequence contains no elements

查看:145
本文介绍了删除提交整行错误序列不包含任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满了Income_Names的组合框。当我单击删除按钮时,我希望删除整个记录。这就是我所拥有的并且我不断得到这个错误"序列不包含任何元素"在红色。

表名是收入,收入的列是Income_ID,Income_Name和Income_Day
当用户从组合框中选择收入名称并单击删除时,我希望与名称关联的记录为被删除。感谢任何帮助过的人。
B




Code Snippet

解决方案

< blockquote>

错误表示数据库中没有与您指定的条件匹配的记录。如果查询没有返回任何行,Single()运算符将抛出异常。您可以使用SingleOrDefault(),它将返回'Nothing'而不是抛出异常。你必须处理这种情况,或者你只是通过调用DeleteOnSubmit引起异常。





 I have a combobox full of Income_Names. When I click the delete button I want the entire record to be deleted.  This is what I have and I keep getting this error "sequence contains no elements" in the red.

The tables name is Income and the Income's columns are Income_ID, Income_Name and Income_Day
When the user selects the Income Name from the combobox and clicks delete I want the record associated with the Name to be deleted. Thank you to anyone who helps.
B

Code Snippet

解决方案

The error means that there is no record in the database matching the condition you specified.  The Single() operator throws the exception if the query returns no rows.  You could use SingleOrDefault() instead, and it would return 'Nothing' instead of throwing the exception.  You'd have to handle that case though or you'd just cause an exception with the call to DeleteOnSubmit.

 

 

 


这篇关于删除提交整行错误序列不包含任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆