我有一个从存储过程中读取的List。它只是一个选择声明。我不知道为什么我收到错误“在所选数据源中找不到字段或属性名称'Ticket ID'。”我正在做的是用我的代码用预定义的列填充gridview。
public List<SelectQueuedTickets> GetQueuedTickets()
{
List<SelectQueuedTickets> QueuedTicketsList = new List<SelectQueuedTickets>();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (SqlCommand com = new SqlCommand("[Reader].[usp_SelectQueuedTickets]", con))
{
con.Open();
com.CommandType = CommandType.StoredProcedure;
SqlDataReader rd = com.ExecuteReader();
while (rd.Read())
{
this.TicketID = Convert.ToString(rd["Ticket ID"]);
this.PriorityID = Convert.ToInt32(rd["Priority"]);
this.FormType = Convert.ToString(rd["Form Type"]);
this.Summary = Convert.ToString(rd["Summary"]);
this.CreationDate = Convert.ToDateTime(rd["Creation Date"]);
this.OwnerGroup = Convert.ToString(rd["Owner Group"]);
this.Owner = Convert.ToString(rd["Owner"]);
this.Creator = Convert.ToInt32(rd["Creator"]);
this.AffectedUser = Convert.ToInt32(rd["Affected User"]);
this.OwnerEmail = Convert.ToString(rd["Owner Email"]);
this.AffectedUserEmail = Convert.ToString(rd["Affected User Email"]);
QueuedTicketsList.Add(this);
}
}
}
return QueuedTicketsList;
}
protected void LoadQueuedTickets()
{
SelectQueuedTickets selectqueuedtickets = new SelectQueuedTickets();
GridView1.DataSource = selectqueuedtickets.GetQueuedTickets();
GridView1.DataBind();
}
答案 0 :(得分:0)
您返回和期望从存储过程返回的内容之间似乎存在不匹配。 我会逐字段比较,看看没有丢失或拼写错误的列名。 在Management studio中运行proc并将其与您在代码中引用的字段进行比较