插入操作后检索 sqldatasource 中的自动编号
在我的 asp.net 应用程序中,我想使用详细信息视图来显示/插入/更新数据库中的数据。
阅读文档后:
http://msdn.microsoft。 com/en-us/library/fkzs2t3h%28v=VS.85%29
它在sqlserver中运行良好,但是当我使用oracle时使用“oledb”提供商,发生错误(我已将“@xxx”等命名参数替换为“?”)。
看来错误是由这个命令引起的:
InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = SCOPE_IDENTITY()"
该命令首先将新数据插入数据库,然后检索 'autonumber' 。
在oracle中,它不起作用,所以我这样修复它:
InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = seq_employees.currval() from dual"
但它仍然不起作用。
有什么想法吗?
In my asp.net application,I want to use the detailsview to show/insert/update data in the db.
After read the docs:
http://msdn.microsoft.com/en-us/library/fkzs2t3h%28v=VS.85%29
IT works well in sqlserver, but when I use oracle using the "oledb" provider,error occurs(I have replaced the named parameter like '@xxx' to '?').
It seems that the error is caused by this command:
InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = SCOPE_IDENTITY()"
The command first insert the new data to the db ,then retrieve the 'autonumber' .
In oracle, it does not work, so I fix it like this:
InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = seq_employees.currval() from dual"
But it still does not work.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此问题:
最佳实践:.NET:如何针对 Oracle 数据库返回 PK?
基本上,您使用 RETURNING key INTO param,并为 param 设置输出参数。
See this question:
Best practices: .NET: How to return PK against an oracle database?
Basically, you use the RETURNING key INTO param, and set up an output parameter for param.