【问题标题】:System.Web.HttpException was unhandled by user code. Message="A field or property with the nameSystem.Web.HttpException 未被用户代码处理。 Message="具有名称的字段或属性
【发布时间】:2010-01-03 04:31:53
【问题描述】:

当我在 XP 机器上运行 ASP.NET/C#/SQL 项目时遇到以下异常:

System.Web.HttpException was unhandled by user code
Message="A field or property with the name 'DisplaySchemaTables()' was not found on the selected data source."
Source="System.Web" ...

你能告诉我可能是什么问题吗?这是导致此问题的代码。异常发生在 DataBind() 上:

protected void Load_GridData()
{
    GridView1.DataSource = ADONET_methods.DisplaySchemaTables();
    GridView1.DataBind();
}

ADONET_methods.cs 文件:

public static SqlDataReader DisplaySchemaTables()
{
    SqlDataReader dr = null;
    SqlCommand cmd = null;
    SqlConnection conn2 = null;
    string SchemaName = "Person";
    string connString = "Data Source=.;AttachDbFilename=\"C:\\Program Files\\Microsoft...;Catalog=AdventureWorks;Integrated Security=true;Connect Timeout=30;User Instance=False";
    string errorMsg;
    try
    {
        conn2 = new SqlConnection(connString);
        cmd = conn2.CreateCommand();
        cmd.CommandText = "dbo.getTableNames";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = conn2;
        cmd.Parameters.Add(new SqlParameter("@SchemaName", SchemaName));
        conn2.Open();
        dr = cmd.ExecuteReader();
    }
    catch (Exception ex)
    {
        errorMsg = ex.Message;
    }
    return dr;
}

【问题讨论】:

    标签: c# asp.net sql data-binding


    【解决方案1】:

    听起来您在标记为“DisplaySchemaTables()”的 GridView 中有一些正在数据绑定的内容。 可能吗?

    【讨论】:

    • 非常有帮助,杰瑞德。问题是在我的 boundfield 命令中,我指定了 datafield="DisplaySchemaTables()"。但是,为来自不同命名空间和不同类的方法包含数据字段的语法是什么?
    【解决方案2】:

    Ghat 异常意味着您要求的字段不是返回数据集中的字段之一。也许在您的标记中,您将列 datafieldname 设置为缺少的字段?

    【讨论】:

    • 非常有帮助,加布里埃尔。问题是在我的 boundfield 命令中,我指定了 datafield="DisplaySchemaTables()"。但是,为来自不同命名空间和不同类的方法包含数据字段的语法是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多