Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How to pass DB output paramenter messga from WEB API to JSON

$
0
0

HI Team,

I've return code and return message as output parameters coming from my Stored proc and now i need to calling them to my them using ADO .net into my WEBAPI controoller. From WEB API to Ajax call finally display on my html page .

I'm unable to give link between these theree please help. Here are my code snippets

I'm using database.outputpameter, i need to use this only not any from ado.net

                                                           

I tried using throw exception but i'm notgetting result as expected.

public static AttributeCollection AdminSearch(int Pid, string email, string UserID)
        {
            AttributeCollection col = new AttributeCollection();
            try
            {
                Microsoft.Practices.EnterpriseLibrary.Data.Database db = SqlDataHelper.CreateDatabase();
                string sp = "getData";

                using (DbCommand cmd = db.GetStoredProcCommand(sp))
                {

                    if (!string.IsNullOrEmpty(UserID))
                        //  db.AddInParameter(cmd, "UserID", DbType.String, UserID);
                        if (Panelistid == 0)
                        {
                            db.AddInParameter(cmd, "pid", DbType.Int32, null);
                            db.AddInParameter(cmd, "email", DbType.String, email);
                        }
                    else
                        {
                            db.AddInParameter(cmd, "pid", DbType.Int32, Panelistid);
                            db.AddInParameter(cmd, "email", DbType.String, null);
                        }
                    db.AddOutParameter(cmd, "returnCode", DbType.Int32, 4);
                    db.AddOutParameter(cmd, "returnMessage", DbType.String, 250);


                    cmd.CommandTimeout = 700;
                    using (IDataReader rdr = db.ExecuteReader(cmd))
                    {
                       // int _rtncode = int.Parse(db.GetParameterValue(cmd, "returnCode").ToString());
                       // string _rtnstring= (db.GetParameterValue(cmd, "returnMessage").ToString());
                        // if (int.Parse(db.GetParameterValue(cmd, "returnCode").ToString()) != 200)
                        //  throw new Exception(db.GetParameterValue(cmd, "returnMessage").ToString());

                        while (rdr.Read())
                                col.Add(new Attribute(rdr));

                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return col;
        }


Sundari



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>