当我在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;
}
答案 0 :(得分:1)
Ghat异常意味着您要求的字段不是返回的数据集中的字段之一。也许在您的标记中,您将列datafieldname设置为缺少的字段?
答案 1 :(得分:1)
听起来你在标有“DisplaySchemaTables()”的GridView中有数据绑定。类似于<%#Eval(“DisplaySchemaTables()”)%>可能?