C# 在数据源上找不到字段/属性

C# 在数据源上找不到字段/属性,c#,stored-procedures,aspxgridview,C#,Stored Procedures,Aspxgridview,我正在更新一个旧程序,该程序从不同的表(使用存储过程)收集信息,并将其显示在ASPxGridView上。我又添加了三列,并尝试将它们绑定到GridView。但是,我得到一个“未找到字段/属性”,无法继续 起初,我以为没有检索到数据,但调试表明,我用来填充ASPxGridView的List对象确实包含我想要添加的数据 protected void search_Click(object sender, EventArgs e) { CommentsDataSource.SelectParam

我正在更新一个旧程序,该程序从不同的表(使用存储过程)收集信息,并将其显示在ASPxGridView上。我又添加了三列,并尝试将它们绑定到GridView。但是,我得到一个“未找到字段/属性”,无法继续

起初,我以为没有检索到数据,但调试表明,我用来填充ASPxGridView的List对象确实包含我想要添加的数据

protected void search_Click(object sender, EventArgs e)
{
   CommentsDataSource.SelectParameters.Clear();
   CommentsDataSource.SelectMethod = "SelectCommentsByProject";
   CommentsDataSource.SelectParameters.Add("pProjectId", System.Data.DbType.String, searchStringTextBox.Text.Trim());
   CommentsDataSource.Databind();
}
搜索还有其他几种选择,但我主要关心的是在处理其余的问题之前,至少让一种方法起作用

private List<Comment> SelectCommentsByProject(string pSearchString)
{
   List<Comments> comments = null;

   if(!string.IsNullOrEmpty(pSearchString))
   {
      System.Data.EntityClient.EntityConnection ecnxn = (System.Data.EntityClient.EntityConnection)esmEntityManager.Connection;
      System.Data.SqlClient.SqlConnection cnxn = (System.Data.SqlClient.SqlConnection)ecnxn.StoreConnection;

      using (cnxn)
      {
          cnxn.Open();
          SqlCommand cmd = new SqlCommand();
          cmd = new SqlCommand("usp_esm_comment_getByProjectID", cnxn);
          cmd.Parameters.Add(new SqlParameter("@ProjectID", pSearchString));

          try
          {
              cmd.CommandType = System.Data.CommandType.StoredProcedure;

              SqlDataAdapter da = new SqlDataAdapter();
              da.SelectCommand = cmd;

              System.Data.DataSet ds = new System.Data.DataSet();
              da.Fill(ds);

              for (int i = 0; i < ds.Tables.Count; i++)
              {
                    if (ds.Tables[i] != null && ds.Tables[i].Rows.Count > 0)
                    {
                          comments = new List<Comment>();
                          foreach (System.Data.DataRow row in ds.Tables[i].Rows)
                          {
                               Comment comment = new Comment();
                               comment.CommentID = (int)row["CommentId"];
                               comment.ComplianceID = (Guid)row["ComplianceID"];
                               comment.CommentText = (row["Comment"] is DBNull) ? null : row["Comment"].ToString();
                               comment.CreatedBy = (row["CreatedBy"] is DBNull) ? null : row["CreatedBy"].ToString();
                               comment.CreatedOn = Convert.ToDateTime((row["CreatedOn"] is DBNull) ? null : row["CreatedOn"].ToString());
                                    comment.LastModifiedBy = (row["LastModifiedBy"] is DBNull) ? null : row["LastModifiedBy"].ToString();
                               comment.LastModifiedOn = Convert.ToDateTime((row["LastModifiedOn"] is DBNull) ? null : row["LastModifiedOn"].ToString());
                               comment.RequestID = (row["RequestID"] is DBNull) ? null : row["RequestID"].ToString();
                               comment.TypeOfService = (row["TypeOfService"] is DBNull) ? null : row["TypeOfService"].ToString();
                               comment.ProjectID = (row["ProjectID"] is DBNull) ? null : row["ProjectID"].ToString();
                               comment.ProjectManager = (row["PM"] is DBNull) ? null : row["PM"].ToString();
                               comment.TaskManager = (row["TMFullName"] is DBNull) ? null : row["TMFullName"].ToString();
                               comments.Add(comment);
                           }
                     }
              }
                        ds.Dispose();
                        cnxn.Close();
                    }
                }
            }
            return comments;
}

投影是场还是属性?它必须是属性才能使用GridView

能否显示smoe相关的代码段?对于格式错误的代码,我提前表示歉意。您是以编程方式创建GridView列,还是在一段aspx代码中定义的?你能把aspx代码,也许不是全部,但只是projectId列。。。它可以很简单,比如
Eval
引用一个有输入错误的属性…@Tallmaris这些列是在aspx中定义的,但我不认为这是问题所在,因为以前的(工作)列是以几乎完全相同的格式定义的。@Yawus,我在ProjectId之前在两个地方看到了这个p,它是否打算
pProjectId
?是的,它是包含预期搜索字符串的变量。
<dxwgv:ASPxGridView ID="commentsASPxGridView" runat="server" AutoGenerateColumns="False" DataSourceID="CommentsDataSource">
   <Columns>
      <dxwgv:GridViewDataTextColumn FieldName="ProjectID" Caption="Project ID" VisibleIndex="7" Name="ProjectID">
      </dxwgv:GridViewDataTextColumn>
   </Columns>
</dxwgv:ASPxGridView>

<dxprt:ASPxGridViewExporter ID="gridExport" runat="server" GridViewID="commentsASPxGridView"></dxprt:ASPxGridViewExporter>        
<asp:ObjectDataSource ID="CommentsDataSource" runat="server" SelectMethod="SelCommentsByProject"  OnDataBinding="DataBindTest"
    TypeName="ESMWeb.ESMCommentService.CommentServiceClient">
    <SelectParameters>
        <asp:Parameter Name="pProjectId" DbType="String"/>
    </SelectParameters>
</asp:ObjectDataSource>