2012-02-12 38 views
-4

我一直收到此錯誤消息。我按照指示,但它似乎仍然不工作?這是什麼解決方案?這裏是我的代碼LINQ中的Datacontext。 「在當前上下文中不存在」

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Data.Linq; 
using System.Data.Linq.Mapping; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      MyDatabaseDataContext = new MyDatabaseDataContext(@"C:\Users\John\Documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\MyDatabase.mdf"); 
     } 


    } 
} 

這裏的堆棧跟蹤

Error 1 'WindowsFormsApplication1.Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs 92 55 WindowsFormsApplication1 
+0

你可以發佈一個完整的堆棧跟蹤。 – DamienG 2012-02-12 04:48:08

+0

remove system.linq – 2012-02-12 04:49:02

+0

在InitializeComponent中生成了什麼?你有什麼異常? – Maggie 2012-02-12 04:49:46

回答

2

,如果你在設計中添加事件處理程序,然後刪除處理方法會發生這種情況。 由於您沒有刪除將該方法添加到事件的自動生成代碼,因此會出現編譯器錯誤。

轉到.Designer.cs文件並刪除包含該錯誤的行。

+0

謝謝!有效! – user962206 2012-02-12 05:04:22

相關問題