ASP.NET LINQ 删除行
Dim db As New SQLDataContext
Try
Dim deleteBoatPics = (From boat In db.Photos
Where boat.boatid = id)
db.Photos.DeleteOnSubmit(deleteBoatPics)
db.SubmitChanges()
Catch ex As Exception
End Try
我收到一条错误消息: 无法将“System.Data.Linq.DataQuery`1[WhiteWaterPhotos.Photo]”类型的对象转换为“WhiteWaterPhotos.Photo”类型。
我有两个单独的 db.SubmitChanges() 因为当按下按钮时,我让它从 1 个表中删除记录,然后再删除下一个表。
我迷路了,有人可以帮助我吗?
Dim db As New SQLDataContext
Try
Dim deleteBoatPics = (From boat In db.Photos
Where boat.boatid = id)
db.Photos.DeleteOnSubmit(deleteBoatPics)
db.SubmitChanges()
Catch ex As Exception
End Try
I'm getting an error that says:
Unable to cast object of type 'System.Data.Linq.DataQuery`1[WhiteWaterPhotos.Photo]' to type 'WhiteWaterPhotos.Photo'.
I have two separate db.SubmitChanges() because when the button is pressed, I have it delete the records from 1 table, and then the next.
I'm lost, can someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
或者对于元素列表:
try this:
Or for a list of elements:
尝试一下,
我不太了解 vb.net,但在 C# 中,在该查询的末尾会有一个“选择船”并使用
全部删除(...)
try
I don't know vb.net that much but in c# is would have a "select boat" at the end of that query and use
RemoveAll(...)