2011-11-18 312 views
-1

错误信息是:列“”不属于表“,即使它存在于该表和查询

类型的异常‘System.Web.HttpUnhandledException’被抛出 友好的消息: System.ArgumentException:Column'testfile'does does not belong to table。在System.Data.DataRow.GetDataColumn(String columnName)at Registration_test.FillImage()in c在System.Data.DataRow.get_Item(String columnName)上不存在 c :\ inetpub \ wwwroot \ testWeb \ Events \ Registration.aspx.cs:第49行 Registration_test.Page_PreInit(Object sender,EventArgs e)in c:\ inetpub \ wwwroot \ testWeb \ test \ Registration.aspx.cs:第39行 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)at System.Web .Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)at System.Web.UI.Page.OnPreInit(EventArgs e)at System.Web.UI.Page.PerformPreInit()at System.Web.UI.Page .ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) 目标站点:布尔的HandleError(System.Exception的)来源:System.Web程序 错误堆栈Trace是:在System.Web.UI.Page.HandleError(例外五) 在系统。 Web.UI.Page.ProcessRequestMain(布尔型 includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest(布尔 includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) 在System.Web.UI.Page.ProcessRequest()在 System.Web.UI.Page.ProcessRequest( HttpContext上下文) ASP.events_registration_aspx.ProcessRequest(HttpContext上下文) c:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727 \ Temporary ASP.NET Files \ testWeb \ 761ce6e4 \ d915dd85 \ App_Web_posk8hm6.6.cs:第0行 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean & completedSynchronously)

我已经得到了上述错误的电子邮件时,该网站在IIS托管,但我DONOT得到它,当我在本地甚至online.The错误校验码说testfile的列亘古不属于即使查询返回列也是可数据的。

任何人都可以帮助可能是什么原因..

//////////////////////这是我的代码////// /////////////////////////0

public partial class Registration_Registration : System.Web.UI.Page 
{ 
    protected void Page_PreInit(object sender, EventArgs e) 
    { 

     FillImage(); 
    } 
    protected void FillImage() 
    { 

     string Query = "select t.header_image_file as 'HeaderImage',t.image,c.testfile from registrars c left join trade t on c.tradeid = t.tradeid and c.mainitemid = t.mainitemid "; 


     DataTable result = GetDataTable(Query); 

     if (result != null && result .Rows.Count > 0) 
     { 
      if (result .Rows[0]["testfile"] != null) 
      { 
      this.Theme = result .Rows[0]["testfile"].ToString().Trim(); 
      this.MasterPageFile = result .Rows[0]["testfile"].ToString().ToLower().Trim() + ".master"; 
      } 
     } 
    } 
} 
protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
    } 
}} 
+2

柱发生了什么,你特林在你的代码做列在您的查询? Registration.aspx.cs:第49行只是检查一个请更新您的答案 –

+0

我是downvote:您从系统中复制/粘贴错误消息,甚至不读取它:“列'testfile'不属于表” - >您没有在您的生产数据库中创建您的专栏!并在标题中更加明确。 –

+0

remi bourgarel希望你喜欢我的新标题。 –

回答

1

好的,乍一看我们发现错误与不在表格中的列有关。

为了解决这个问题,我建议你首先在管理工作室中运行查询,检查返回列的名称与您尝试在ASP.Net页面中访问的列的名称。 如果列名都是正确的备份数据然后删除并重新创建表和访问此表的存储过程,并希望这将解决问题。

在开发过程中意外更新数据库中的列等非常容易,并且不会将更改推送到生产数据库。

如果这不解决问题,您将能够获得更好的帮助,如果您发布表结构,查询和访问查询的代码,以便我们可以更有效地诊断问题。

UPDATE: 这些都是您选择

strt.header_image_file as 'HeaderImage', 
t.image, 
c.themefile 

然而,在你的代码试图访问一个名为testfile的

+0

我已经运行了查询管理工作室对数据库,并在表中存在列,这个错误我不会总是这个错误间歇性地发生。 –

+0

@PakaujiPakau我用我认为会导致问题的内容更新了我的答案。让我知道如果它不正确。谢谢 – Purplegoldfish

+0

实际上这是一个错字编辑错误,我已更新后的列是测试文件 –