Wednesday, December 7, 2022

How to pass output parameter in C# from SQL server Stored procedure

 public static DataTable GetEmployeeListWithPaging(string PostHeld, int startIndex, int pageSize , out int totalCount)

        {

            SqlParameter parTotalCount = new SqlParameter("TotalCount", SqlDbType.Int);


            parTotalCount.Direction = ParameterDirection.Output;


            SqlParameter[] param = { new SqlParameter("postheld", PostHeld),

                new SqlParameter("StartIndex", startIndex),

                new SqlParameter("PageSize",pageSize) ,

              parTotalCount };

            //new DataAccess().Read("read_cadre_info_paging", param);

            //totalCount = Convert.ToInt32(parTotalCount.Value);

            DataTable dt = new DataAccess().Read("read_cadre_info_paging", param).Tables[0];

            totalCount = Convert.ToInt32(parTotalCount.Value);

            return dt;


        }

// calling of above function

 int totalRowCount = 0;

            int startRowNumber = ((currentPage) * pageSize) + 1;

            DataTable dt = Repository.GetEmployeeListWithPaging(PostHeld,startRowNumber, pageSize,out totalRowCount);


reference:-https://www.c-sharpcorner.com/blogs/example-on-how-to-use-output-parameter-in-stored-procedure-in-c-sharp

https://www.c-sharpcorner.com/UploadFile/rohatash/get-out-parameter-from-a-stored-procedure-in-Asp-Net/

https://www.codeproject.com/Questions/539269/outputplusparameterplusinplusstoredplusprocedurepl



No comments:

Post a Comment