提问人:Akash Roman 提问时间:11/17/2023 最后编辑:Mark SeemannAkash Roman 更新时间:11/17/2023 访问量:13
当我将字符串作为输入参数发送时,如何获得成功消息?
How do i get a Success message when i send a string as a input parameter?
问:
我正在发送一个字符串作为输入参数,我应该在邮递员集合中得到一个“SUCCESS”消息作为我的输出......
这是我的DAL。
public class ResponseDAL
{
public static DataTable ResponseMessage(string Message)
{
DataTable dtMessage = new DataTable();
try
{
string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection myConnectionGroupData = new SqlConnection(ConnectionString))
{
using (SqlCommand myCommandGroupData = new SqlCommand("", myConnectionGroupData))
{
myCommandGroupData.CommandType = CommandType.StoredProcedure;
myCommandGroupData.Parameters.AddWithValue("@Option", " ");
myCommandGroupData.Parameters.AddWithValue("@Message", Message );
myCommandGroupData.CommandTimeout = 0;
myConnectionGroupData.Open();
SqlDataAdapter sdaCategory = new SqlDataAdapter(myCommandGroupData);
sdaCategory.Fill(dtMessage);
myConnectionGroupData.Close();
}
}
}
catch (Exception ex)
{
throw;
}
return dtMessage;
}
}
这是我的BAL。
public class ResponseBAL
{
public static DataTable ResponseMessage(string Message)
{
DataTable dtMessage = new DataTable();
try
{
dtMessage = ResponseDAL.ResponseMessage(Message);
}
catch (Exception ex)
{
throw;
}
return dtMessage;
}
}
这是我的控制器
public class ResponseController : ApiController
{
#region "Response"
[Route("api/Response/ResponseMessage")]
[HttpPost]
public DataTable BranchList([FromBody]dynamic Data)
{
string Message = Data.Message;
DataTable dtMessage = new DataTable();
try
{
dtMessage = ResponseBAL.ResponseMessage(Message);
}
catch (SqlException ex)
{
}
return dtMessage;
}
#endregion
}
我正在发送一个字符串作为输入参数,我应该在邮递员集合中得到一个“SUCCESS”消息作为我的输出......
答:
0赞
Mark Seemann
11/17/2023
#1
创建对象时,需要提供存储过程的名称:SqlCommand
using (var myCommandGroupData = new SqlCommand(sprocName, myConnectionGroupData))
或者,可以在创建对象后设置 CommandText:
myCommandGroupData.CommandText = sprocName;
评论