Call store proc from asp.net which returns output parameter

i am trying to call a proc from my webpage and expect couple output parameters. I am not sure how to read those parameters once i execute the proc.

here is the code

 DataSet ds1 = GetPasswordRuleCheck(webId, Password.Text.Trim(), "login");



        public static DataSet GetPasswordRuleCheck(int webid,string currentPassword,string action)
        {
                              var sqlParms = new object[]
                               {
                                new SqlParameter("@wID", webid),
                                new SqlParameter("@Password", currentPassword),
                                new SqlParameter("@Action", action),
                                new SqlParameter("@Result", 0),     -- output parameter
                                new SqlParameter("@Message", ""),  -- output parameter
                               };
            return SqlHelper.ExecuteDataset("dbo.spASPasswordRuleCheck", sqlParms);
 
        }
pratikshahseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Unfortunately it's not entirely clear what you need but I gave it my best shot. It could depend on the definition of your stored procedure if this works.
        public static DataSet GetPasswordRuleCheck(int webid,string currentPassword,string action)
        {
            // create output parameters first to be able to set properties

            SqlParameter op1 = new SqlParameter("@Result", 0);     // output parameter
            op1.Direction = ParameterDirection.Output;

            SqlParameter op2 = new SqlParameter("@Message", "");   // output parameter
            op2.Direction = ParameterDirection.Output;

            // added these for my test only, may or may not be applicable for your situation
            op2.DbType = DbType.String;
            op2.Size = 100;

            // now use 'op' variables in the array
            var sqlParms = new object[]
            {
                new SqlParameter("@wID", webid),
                new SqlParameter("@Password", currentPassword),
                new SqlParameter("@Action", action),
                op1,
                op2
            };

            // store dataset in local variable to be able to examine before returning it to calling function
            DataSet dsReturn = SqlHelper.ExecuteDataset("dbo.spASPasswordRuleCheck", sqlParms);
            
            // debug any output values, could also be stored in global/class variable for example
            foreach (SqlParameter p in sqlParms) {
                if (p.Direction == ParameterDirection.Output || p.Direction == ParameterDirection.InputOutput) {
                    Console.WriteLine("param '{0}' returned value '{1}'", p.ParameterName, p.Value);
                }
            }
            
            // optional, also look at dataset returned?
            foreach (DataTable t in dsReturn.Tables) {
                foreach (DataRow r in t.Rows) {
                    foreach (object c in r.ItemArray) {
                        Console.Write("|" + c.ToString());
                    }
                    Console.WriteLine("|");
                }
            }

            return dsReturn;
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.