使用DataSet获取objectdatasource中最后插入的项目的id
我在 SO 上对她进行了很多搜索,但我似乎找不到任何人这样做过。我确信这是一个常见问题,但我无法找出正确的关键字来搜索解决方案,因此如果这是重复的,我很抱歉。
我有一个数据集,其中使用了“生成插入”、“更新”和“删除”语句以及“刷新数据表”选项,以便在使用 ObjectDatasource 时可以检索最后插入的 ID。
但是,当我处理 ObjectDataSource-Inserted 方法时,我得到 1 作为返回值,我认为这是受影响的行。我不想要这个,我想要 ID,以便我可以在我的代码中使用它。
我查看了插入方法的生成代码,它在插入后执行 SELECT,但它返回整行而不是 ID,那么我怎样才能获取这一行来检索值呢?
I've done a lot of searching on this her on SO but I can't seem to find anyone who has done this. I'm sure it's a common problem but I can't figure out the right keywords to search for the solution so I'm sorry if this is a duplicate.
I have a dataset where I've used the Generate Insert, Update, and Delete statements as well as the Refresh the Data Table options so that I can retrieve the last inserted ID when I'm using an ObjectDatasource.
however, when I'm handling the ObjectDataSource-Inserted method, I'm getting a 1 as a return value, which I assume is the affected rows. I don't want that, I want the ID so that I can use it in my code.
I looked at the generated code for the insert method and it is doing a SELECT after inserting, but it returns the whole row not the ID, so how can I get at this row to retrieve the value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去做过的事情是使用静态方法进行 CRUD 操作。
和 C# 代码:
我还没有尝试编译此代码,所以如果我犯了一些错误,我深表歉意。由于获得了控制权,这种特殊的模式使我摆脱了一些困境。请阅读这篇文章了解更多详情关于这是如何运作的。
Something I've done in the past is to use static methods for CRUD operations.
and the C# code:
I haven't tried compiling this code, so I apologize if I made some errors. This particular pattern has gotten me out of a few predicaments because of the gained control. Please read this article for more details on how this works.