使用Web API使用参数调用存储过程

时间:2016-08-08 04:28:55

标签: c# sql-server stored-procedures asp.net-web-api2

当我在SQL Server中执行此存储过程时:

use Vcom
go
exec abrir_turno @posto = 'pppe', @turno = '3', @data = '2016-06-13'

SQL Server返回一条消息:

  

你的SP设置pppe打开

我正在尝试使用Web Api 2和C#实现它:

public IEnumerable<string> spabrirturno(string posto, string turno, string data, string STATUS_TURNO)
{
   STATUS_TURNO = null;

   return obj.abrir_turno(posto, turno, data, STATUS_TURNO).AsEnumerable();
}

但是我收到了一个错误:

  

无法将IEnumerable类型隐式转换为字符串

照片中的

消息......

enter image description here

1 个答案:

答案 0 :(得分:0)

obj.abrir_turno返回abrir_turno_Result的集合,而不是字符串。您需要从结果中选择所需的值。在AsEnumerable之前,添加

.Select(m => m.WhateverPropertyName)