2011-11-18 34 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

實際上這是一個錯字編輯錯誤,我已更新後的列是測試文件 –

相關問題