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

本文关键字:属性 字段 找不到 数据源 | 更新日期: 2023-09-27 18:17:10

我正在更新一个旧的程序,它从不同的表(使用存储过程)收集信息,并在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;
}

在调试中检查List<Comments>对象,我可以看到它在ProjectID字段中包含有效数据。但是,当我尝试运行它时,我总是得到这个错误。

这是(部分)ascx的标记。

<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>

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

投影是一个字段还是属性?它必须是一个属性,以便与GridView一起工作