开发者

System.Web.HttpException was unhandled by user code. Message="A field or property with the name

I am getting the below exception when I run my ASP.NET/C#/SQL project on an XP box:

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

Can u advise me on what the problem might be? Here is the code causing this. The exception happens on the DataBind():

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

ADONET_methods.cs file:

public st开发者_运维百科atic 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;
}


Sounds like you have something being databound in the GridView labeled "DisplaySchemaTables()". Something like <%# Eval("DisplaySchemaTables()") %> possibly?


Ghat exception means that you are asking for a field that was not one ofthe fields in the returned dataset. Maybe in your markup, you are setting the column datafieldname to a missing field?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜