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

时间:2013-06-06 15:16:23

标签: c# stored-procedures aspxgridview

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

起初,我认为数据没有被检索,但是调试显示我用来填充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>

1 个答案:

答案 0 :(得分:0)

ProjectID是字段还是属性?它必须是属性才能使用GridView