Execute Stored Procedure and display result in View using AngularJS in ASP.Net MVC

Last Reply one month ago By dharmendr

Posted one month ago

Hi,

I have one stored procedure 

CREATE PROCEDURE [dbo].[PayProcess] 
    -- Add the parameters for the stored procedure here
    (@Date Date)
AS
BEGIN
    SELECT 'Procedure Run sucessfully' As 'Procedure'
END
GO

After exccuting stored procedure i am getting o.p like below in sql

Procedure

Procedure Run successfully

After that display the result in View

Note: If I try to execute normal query it was generating result

but if i try to use stored procudure not getting any result

    [HttpPost]
    public JsonResult PayProcess(DateTime date)
    {
        // Call your Procedure. 
        try
        { 
            string result = db.GetPayProcess(date).FirstOrDefault();
            //string result = "select * from Report where Id=2";
            //var result = db.GetPayProcess(date).ToString();
            SqlConnection con = new SqlConnection();
            string connectionstring = ConfigurationManager.ConnectionStrings["CMSR"].ConnectionString;
            con.ConnectionString = connectionstring;
            SqlCommand cmd;
            DataTable dtDet = new DataTable();
            SqlDataAdapter sdaDet = new SqlDataAdapter();
            cmd = new SqlCommand(result, con);
            sdaDet.SelectCommand = cmd;
            dtDet = new DataTable();
            sdaDet.Fill(dtDet);
            List<Dictionary<string, object>> lstReport = GetTableRows(dtDet);
 
            return Json(lstReport, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            return Json(ex.Message, JsonRequestBehavior.AllowGet);
        }
 
    }
    public List<Dictionary<string, object>> GetTableRows(DataTable dtData)
    {
        List<Dictionary<string, object>>
        lstRows = new List<Dictionary<string, object>>();
        Dictionary<string, object> dictRow = null;
 
        foreach (DataRow dr in dtData.Rows)
        {
            dictRow = new Dictionary<string, object>();
            foreach (DataColumn col in dtData.Columns)
            {
                dictRow.Add(col.ColumnName, dr[col]);
            }
            lstRows.Add(dictRow);
        }
        return lstRows;
    }

 

This question does not have replies that have been liked.