从 @tempTable 内的存储过程填充 gridview

发布于 2024-12-25 01:22:56 字数 322 浏览 4 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往昔成烟 2025-01-01 01:22:56

简单的答案是,除非创建临时表并将其保留在数据库中,否则您无法像连接普通表那样连接到它。 @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.

梦萦几度 2025-01-01 01:22:56

问题是由连接类型引起的。它是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文