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

StackOverflow https://stackoverflow.com/questions/204155

Question

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.

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. I assume that it has trouble determining the data types being used since the SP is not based on a real schema.

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.

Was it helpful?

Solution

For info, you might consider using a "table variable" rather than a temporary table (i.e. @FOO rather than #FOO) - this might help a little, and it certainly helps a few tempdb issues.

With temporary tables - no there is no way of explicitly declaring the SPs schema. I would perhaps suggest using a simplified version of the SP while you generate your wrapper classes - i.e. have it do a trivial SELECT of the correct shape.

Alternatively, I would use LINQ to consume a UDF, which does have explicit schema.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top