简体   繁体   English

如何让C#Query组件识别从sql存储过程中的临时表返回的数据列

[英]How do I get the C# Query component to recognise columns returned data from a temporary table in a sql stored procedure

I've created a stored procedure similar to the one below (I'm using this cut down version to try and figure our the problem). 我已经创建了一个类似下面的存储过程(我正在使用这个减少版本来尝试解决我们的问题)。

CREATE PROCEDURE bsp_testStoredProc
AS
BEGIN

CREATE TABLE #tmpFiles  
(
    AuthorName NVARCHAR(50), 
    PercentageHigh INT
) 

-- Insert data into temp table

SELECT AuthorName, PercentageHigh FROM #tmpFiles 
ORDER BY PercentageHigh DESC

DROP TABLE #tmpFiles

RETURN 0
END

From my C# code in VS2008, I'm trying to use the Query component with the Use Existing Stored Procedure option to connect this up to a DataTable / DataGridView to display the results. 从我在VS2008中的C#代码中,我尝试使用Query组件和Use Existing Stored Procedure选项将其连接到DataTable / DataGridView以显示结果。

However, because I'm selecting from a temporary table, in the Query component properties Visual Studio does not display any columns being returned from the stored procedure. 但是,因为我从临时表中进行选择,所以在查询组件属性中,Visual Studio不会显示从存储过程返回的任何列。 I assume that it has trouble determining the data types being used since the SP is not based on a real schema. 我认为它确定正在使用的数据类型有困难,因为SP不是基于真实模式。

Connecting to different stored procedures that select from real tables do show the columns correctly. 连接到从实际表中选择的不同存储过程会正确显示列。

Does anyone know away around this? 有谁知道这个吗? Is there some sort of hint I can add somewhere to explicitly state what sort of data will be returned? 是否有某种提示我可以在某处明确说明将返回哪种数据?

Thanks in advance. 提前致谢。

For info, you might consider using a "table variable" rather than a temporary table (ie @FOO rather than #FOO) - this might help a little, and it certainly helps a few tempdb issues. 有关信息,您可能会考虑使用“表变量”而不是临时表(即@FOO而不是#FOO) - 这可能会有所帮助,它肯定有助于一些tempdb问题。

With temporary tables - no there is no way of explicitly declaring the SPs schema. 使用临时表 - 没有办法明确声明SP模式。 I would perhaps suggest using a simplified version of the SP while you generate your wrapper classes - ie have it do a trivial SELECT of the correct shape. 我可能会建议在生成包装类时使用SP的简化版本 - 即让它对正确的形状进行简单的SELECT。

Alternatively, I would use LINQ to consume a UDF, which does have explicit schema. 或者,我会使用LINQ消耗UDF,里面确实有明确的架构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#和SQL Server:如何通过使用C#调用存储过程来从SQL表中获取值? - C# and SQL Server: How do I get values from my SQL Table, by calling my stored procedure with C#? 获取从存储过程SQL Server 2008 silvelight C#Linq返回的数据 - get the data that was returned from the stored procedure SQL Server 2008 silvelight C# Linq 如何从C#调用存储过程,并获取返回值? - How to call stored procedure from C#, and get the returned value? 如何从C#中的SQL Server存储过程获取返回的结果 - How to get the result returned back from a SQL Server stored procedure in C# 仅当xml数据从C#传递到存储过程时,才在存储过程中使用Delete table查询 - Use Delete table query in stored procedure only when xml data is passed from C# to stored procedure 如何使用 c# 中的 MySQL 存储过程将表作为输入发送到存储过程? 我有 T-SQL 工作 - How do I use a MySQL stored procedure from c# which sends a table as input to the store procedure? I have T-SQL working 如何将存储过程中的值从SQL返回到C# - How do I return values from my stored procedure from SQL to c# 如何使用c#中的存储过程从网格中的两个表中获取数据 - how to get data from two table in the grid by using stored procedure in c# 我应该如何从 C# 中存储过程的选择查询中获取值 - How should I get the values from the select query of the stored procedure in c# 如何从C#中的存储过程中获取所选值? - How do I get the selected value from a stored procedure in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM