C# - Passing parameter to stored procedure and return IEnumerable

Nel

can I directly pass the parameter in the query as shown below?

There is error so anyone could help?

public IEnumerable ListTop10countries(string direction)
{
    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCON"].ToString()))
    {
        var list = con.Query<OutputCountries>("Usp_GetTop10", direction).AsEnumerable();       
        return list;
    }
}

Error:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Procedure or function 'Usp_GetTop10' expects parameter '@direction', which was not supplied.

The stored proc script as is below:

CREATE proc [dbo].[Usp_GetTop10]
@direction nvarchar(30)
as
begin
SELECT TOP 10 
      [country]    
      ,[Tons]
  FROM [master].[dbo].[a]
  where direction = @direction
  order by [Tons] Desc
end
GO
sangram parmar

try this

public IEnumerable ListTop10countries(string mydirection)
{
    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCON"].ToString()))
    {
         var list = con.Query<OutputCountries>("Usp_GetTop10", new {direction = mydirection}, commandType: CommandType.StoredProcedure).AsEnumerable();
         return list;
    }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

C# - Passing parameter to stored procedure and return IEnumerable

분류에서Dev

Passing multiple value parameter to stored procedure

분류에서Dev

Passing data to a stored procedure that accepts Table Valued Parameter using pyodbc

분류에서Dev

return generic IEnumerable when passing concrete type parameter for a generic method

분류에서Dev

Varchar value not passing into SQL Server stored procedure

분류에서Dev

Stored Procedure OUT parameter always returning NULL

분류에서Dev

Is an empty string considered an empty parameter in a stored procedure?

분류에서Dev

SQL stored procedure: how to concatenate parameter value?

분류에서Dev

How can I call an Oracle stored procedure with object parameter for input in c#?

분류에서Dev

Passing Strings to a Class Method that passes information to stored SQL procedure

분류에서Dev

Passing a parameter to Html.ActionLink when the model is IEnumerable<T>

분류에서Dev

How to pass schema as parameter to a stored procedure in sql server?

분류에서Dev

PHP mysqli prepared statement for stored procedure with out parameter

분류에서Dev

Call MySQL stored procedure with parameter from batch file

분류에서Dev

MySQL stored procedure return variable values from seconds query?

분류에서Dev

Return rowcount from stored procedure T-SQL

분류에서Dev

Passing table valued parameter to stored proc with different number of fields

분류에서Dev

SQL server stored procedure issue in via with c#

분류에서Dev

Pass array as input parameter to an oracle stored procedure using simple jdbc call

분류에서Dev

Not able to call Stored procedure contains Varchar2_table as a parameter from Java

분류에서Dev

Error "Must declare the scalar variable" when creating a stored procedure with table parameter

분류에서Dev

Dynamically Retrieve Parameter Names & Current Values Inside T-SQL Stored Procedure

분류에서Dev

Stored procedure with conditional insert

분류에서Dev

Adding a stored procedure to a database

분류에서Dev

Stored procedure to encrypt data

분류에서Dev

Stored procedure not working

분류에서Dev

Simple If Statement in Stored Procedure

분류에서Dev

Transaction in Stored procedure

분류에서Dev

Call stored procedure with Repository

Related 관련 기사

  1. 1

    C# - Passing parameter to stored procedure and return IEnumerable

  2. 2

    Passing multiple value parameter to stored procedure

  3. 3

    Passing data to a stored procedure that accepts Table Valued Parameter using pyodbc

  4. 4

    return generic IEnumerable when passing concrete type parameter for a generic method

  5. 5

    Varchar value not passing into SQL Server stored procedure

  6. 6

    Stored Procedure OUT parameter always returning NULL

  7. 7

    Is an empty string considered an empty parameter in a stored procedure?

  8. 8

    SQL stored procedure: how to concatenate parameter value?

  9. 9

    How can I call an Oracle stored procedure with object parameter for input in c#?

  10. 10

    Passing Strings to a Class Method that passes information to stored SQL procedure

  11. 11

    Passing a parameter to Html.ActionLink when the model is IEnumerable<T>

  12. 12

    How to pass schema as parameter to a stored procedure in sql server?

  13. 13

    PHP mysqli prepared statement for stored procedure with out parameter

  14. 14

    Call MySQL stored procedure with parameter from batch file

  15. 15

    MySQL stored procedure return variable values from seconds query?

  16. 16

    Return rowcount from stored procedure T-SQL

  17. 17

    Passing table valued parameter to stored proc with different number of fields

  18. 18

    SQL server stored procedure issue in via with c#

  19. 19

    Pass array as input parameter to an oracle stored procedure using simple jdbc call

  20. 20

    Not able to call Stored procedure contains Varchar2_table as a parameter from Java

  21. 21

    Error "Must declare the scalar variable" when creating a stored procedure with table parameter

  22. 22

    Dynamically Retrieve Parameter Names & Current Values Inside T-SQL Stored Procedure

  23. 23

    Stored procedure with conditional insert

  24. 24

    Adding a stored procedure to a database

  25. 25

    Stored procedure to encrypt data

  26. 26

    Stored procedure not working

  27. 27

    Simple If Statement in Stored Procedure

  28. 28

    Transaction in Stored procedure

  29. 29

    Call stored procedure with Repository

뜨겁다태그

보관