views:

405

answers:

2

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 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;
}
+1  A: 

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?

Gabriel McAdams
Very helpful, Gabriel. The problem was that in my boundfield command, I specified datafield="DisplaySchemaTables()". But what is the syntax for including a datafield for a method that comes from a different namespace and different class?
salvationishere
Nevermind, I figured out this answer. Thanks for the help!
salvationishere
+1  A: 

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

Jared
Very helpful, Jared. The problem was that in my boundfield command, I specified datafield="DisplaySchemaTables()". But what is the syntax for including a datafield for a method that comes from a different namespace and different class?
salvationishere
Nevermind, I figured out this answer. Thanks for the help!
salvationishere