我编写了一个代码,可以通过一个过程返回到列表,并且可以正常工作,但是现在我需要返回一个视图列表 * SQL Server
我的代码:
public List<Ticket> GetTicket()
{
List<Ticket> ticketList = new List<Ticket>();
using (_con = new SqlConnection(_connectionString))
{
using (SqlCommand command = new SqlCommand("select * from MyView", _con))
{
command.CommandType = CommandType.TableDirect;
_con.Open();
SqlDataReader reader = command.ExecuteReader();
// reader.Load(command.ExecuteReader());
while (reader.Read())
{
Ticket ticket = new Ticket()
{
//TicketNumber = Convert.ToInt32(reader["numeroTicket"]),
Priority= Convert.ToString(reader["tpr_txt_prioridade"]),
Status = Convert.ToString(reader["status_descri"]),
Client = Convert.ToString(reader["cliente"]),
Topic = Convert.ToString(reader["topico"]),
Responsible= Convert.ToString(reader["usuario_responsavel"]),
OpenDate = Convert.ToDateTime(reader["dt_int"]),
LastInteraction= Convert.ToDateTime(reader["tkt_dat_prazo"])
};
ticketList.Add(ticket);
}
return ticketList;
}
}
}
答案 0 :(得分:-1)
之前
command.CommandType = CommandType.StoredProcedure;
之后
command.CommandType = CommandType.Text;
我只需要从.StoredProcedure
切换到.Text
Ty !!!!!!!!!!!