SqlDataAdapter.FillSchema 与具有临时表的存储过程 [英] SqlDataAdapter.FillSchema with stored procedure that has temporary table

查看:26
本文介绍了SqlDataAdapter.FillSchema 与具有临时表的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了类似于这个问题的问题(在运行时显示来自 SQL Server 查询结果的列的数据类型和大小) 没有一个可靠的解决方案.

I'm running into a problem similar to this question here (Display DataType and Size of Column from SQL Server Query Results at Runtime) which has not had a solid solution.

我想知道是否有人找到了解决方案或变通办法.我可以毫无问题地使用 SqlDataAdapter.Fill(),但是 .FillSchema() 会报告我在存储过程中创建的临时表不存在的错误.

I wonder if anyone has found a solution or a work around for it. I can use SqlDataAdapter.Fill() with no problem, but .FillSchema() will report an error that the temp table I create in the stored procedure doesn't exist.

我的目标是能够用来自源的数据和架构填充 DataTable.

My goal is to be able to fill the DataTable with data and the schema from the source.

推荐答案

存储过程和临时表通常不能与数据库对象的强类型实现很好地混合.

Stored procedures and temp tables generally don't mix well with strongly typed implementations of database objects.

如果您将#temp 表更改为应该可以解决您的问题的表@variable.

If you change your #temp table to a table @variable that should solve your issue.

如何从临时表更改为表变量的示例如下:

An example of how to change from temp table to table variable would be like:

    CREATE TABLE #tempTable (ID INT, Val VARCHAR(50))

    DECLARE @tempTable TABLE(ID INT, Val VARCHAR(50))

这篇关于SqlDataAdapter.FillSchema 与具有临时表的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆