如何将DB输出参数messga从WEB API传递给JSON [英] How to pass DB output paramenter messga from WEB API to JSON
问题描述
HI团队,
我已经返回代码并返回来自我的存储过程的输出参数消息,现在我需要使用ADO .net将它们调用给我们进入我的WEBAPI控制器。从WEB API到Ajax调用终于显示在我的html页面上。
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 .
我无法在这些theree之间给出链接请帮忙。这是我的代码片段
I'm unable to give link between these theree please help. Here are my code snippets
我正在使用database.outputpameter,我只需要使用这个来自ado.net
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();
         试试
          {
              Microsoft.Practices.EnterpriseLibrary.Data.Database db = SqlDataHelper.CreateDatabase();
              string sp =" getData"; $
             使用(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);
                      }¥b $ b                  否则
                      {
                          db.AddInParameter(cmd," pid",DbType.Int32,Panelistid);
                          db.AddInParameter(cmd," email",DbType.String,null);
                      }¥b $ b                   db.AddOutParameter(cmd," returnCode",DbType.Int32,4);
                  db.AddOutParameter(cmd," returnMessage",DbType.String,250);
                  cmd.CommandTimeout = 700;
                 使用(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)
                      // 抛出新的异常(db.GetParameterValue(cmd," returnMessage")。ToString());
$
                      while(rdr.Read())
                              col.Add(new Attribute(rdr));
                  }¥b $ b               }¥b $ b           }¥b $ b           catch(例外情况)
          {
             抛出新的例外(ex.Message);
          }¥b $ b          返回col;
      }
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
推荐答案
美好的一天
Lakshmi ,
此论坛( 从SQL Server <开始获取
/ span> )专注于SQL Server方面,在我看来,您的问题与SQL Server无关,但与应用程序端无关。听起来你最好的选择就是在C#论坛上提问。
This forum (Getting started with SQL Server) focuses in the SQL Server side, and it seems to me like your question has nothing to do with the SQL Server but with the application side. It sound like your best option is to ask the question in C#forum for example.
如果你愿意,我可以把你的问题转到C#论坛或另一个论坛来处理这些技术和你使用的语言。请确认哪个论坛
If you want I can move your question to the C# forum or to another forum which deal with the technologies and language which you use. please confirm which forum
在此期间,您可能需要查看以下帖子,我在那里使用PowerShell解释了这个要求:
如何使用PowerShell控制QUERIES的输出,包括PRINT语句和ERROR按摩
In the meantime, you might want to take a look on the following post, where I explained exactly this requirement using PowerShell: How to control the output of a QUERIES including the PRINT statement and ERROR massages using PowerShell
它可能会给你一些想法
It might give you some ideas
这篇关于如何将DB输出参数messga从WEB API传递给JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!