从 @tempTable 内的存储过程填充 gridview
我有一个使用 C# 和 Microsoft SQL Server 的项目,我想用存储过程填充我的 gridview。
这个过程中有一个表声明(我需要这个@temptable来使用opendatasource从另一个数据库获取一些数据)。
它在 SQL Server Management Studio 中没问题,但当我的过程有 @tempTable 减速时(即使我不使用它表),它不会填充我的 gridview(在 c# 项目中)。
如何在程序中使用 @tempTable 以在 gridview 中使用它?
ps 我也尝试过 @tmp、#tmp、##tmp 表。
I have a project with c# and Microsoft SQL Server, I want to populate my gridview with a stored procedure.
this procedure has a table declaration in it ( I need this @temptable for get some data from another database with opendatasource).
It is OK in SQL Server Management Studio but it doesn't populate my gridview(in c# project) when my procedure has a deceleration of a @tempTable (even I don't use it table).
how can I use @tempTable in procedure to use it in gridview?
p.s. I also tried @tmp, #tmp, ##tmp tables as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的答案是,除非创建临时表并将其保留在数据库中,否则您无法像连接普通表那样连接到它。 @temptable 是本地引用。
如果您知道表定义,则可以设置适当的数据对象;从过程中传回临时表的所有行;将结果存储在数据对象的集合中,并使该集合成为网格的数据源。
这意味着您无法使用服务器资源管理器中的任何拖放功能,但需要编写自己的 SQL 命令来检索该数据并填充集合。
The simple answer is that unless the temporary table is created and left resident within the database, you can't connect to it as you would a normal table. @temptable is a local reference.
If you know the table definition though you could setup an appropriate data object; pass back all rows of the temporary table from the procedure; store the results in a collection of your data object and make that collection the datasource for your grid.
This would mean that you couldn'y use any drag and drop functionality from Server Explorer, but would need to code your own SQL command to retrieve that data and populate the collection.
问题是由连接类型引起的。它是 oledbconnetion,我将其更改为 sqlconnection,现在我可以在存储过程中使用表变量在网格中选择它
the problem coused about type of connection. it was oledbconnetion and I changed it to sqlconnection, now I can use table variables in a stored procedure to select it in a grid