简体   繁体   中英

How to return table multiple rows from a stored procedure and access those values in C# using ADO.NET?

I want to return a table from a stored procedure like inline table value return table but that achieve from stored procedure not a function, so what is the way we can achieve this?

I am trying to use a stored procedure, but it's not working - actually this code is wrong but please provide some proper solution.

ALTER PROCEDURE spForFilterUpdateSorting 
    @action NVARCHAR(MAX),
    @tableName NVARCHAR(MAX),
    @P1_string NVARCHAR(MAX),
    @ReturnOutString NVARCHAR(MAX) OUTPUT
AS
BEGIN
    IF @action = 'SEARCH'
        IF @tableName = 'Student_Details'
            IF EXISTS(SELECT [Name] FROM Student_Details 
                      WHERE [Name] LIKE CONCAT(@P1_string, '%'))    
                SELECT
                    @ReturnOutString = (SELECT [Name] FROM Student_Details 
                                        WHERE [Name] LIKE CONCAT(@P1_string, '%')) // I want to return selected value
            ELSE
                SELECT @ReturnOutString = 'null'
END
    IF @tableName='Student_Details'
            select [Name] from Student_Details where [Name] like CONCAT(@P1_string,'%')
        ELSE
            select null as Name
    END

this method will return table, please let me know if it didn't work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM