2012-08-15 49 views
-4

我有一個錯誤,說我沒有一個名爲'GetUser'的方法,即使它在那裏..錯誤說: 「System.Security.Principal.IPrincipal'確實不包含關於「的getUser」和沒有擴展方法的定義「的getUser」接受類型「System.Security.Principal.IPrincipal」的第一個參數可以發現「我的代碼不在視覺工作室

這是我在用戶類代碼

public static List<User> GetUser() 
    { 
     SqlConnection conn = null; 
     List<User> result = new List<User>(); 
     try 
     { 
      conn = new SqlConnection(); 
      conn.ConnectionString = ConfigurationManager.ConnectionStrings["2ndEardbConnectionString"].ConnectionString; 
      conn.Open(); 
      SqlCommand comm = new SqlCommand(); 
      comm.Connection = conn; 
      comm.CommandText = "select * from User"; 
      SqlDataReader dr = comm.ExecuteReader(); 
      while (dr.Read()) 
      { 
       User u = new User(); 
       u.Name = (string)dr["Name"]; 
       u.UserName = (string)dr["UserName"]; 
       u.Password = (string)dr["Password"]; 
       u.DOB = (DateTime)dr["DOB"]; 
       u.Gender = (string)dr["Gender"]; 
       u.Email = (string)dr["Email"]; 
       u.ContactNumber = (int)dr["ContactNumber"]; 
       u.ProfilePic = (byte)dr["ProfilePic"]; 
       u.Image = (byte)dr["Image"]; 


       result.Add(u); 
      } 
      dr.Close(); 
     } 
     catch (SqlException e) 
     { 
      throw e; 
     } 
     finally 
     { 
      conn.Close(); 
     } 
     return result; 
    } 

並且在表格中,這是我放的代碼

protected void Button1_Click(object sender, EventArgs e) 
    { 
     List<User> results = User.GetUser(); 
     foreach (User u in results) 
     { 
      if (TextBox8.Text.ToString() == u.UserName.ToString()) 
      { 
       Label13.Visible = true; 
       break; 
      } 
      else 
      { 
       Label12.Visible = true; 
      } 
     } 
    } 

但是,User.GetUser()發生錯誤:

說明沒有方法。

我如何去在視覺工作室C# 請幫 解決這一謝謝

+0

你把用戶類放在哪裏?你是否缺少使用指令? – Thousand 2012-08-15 10:31:06

+0

'GetUser'函數看起來正確。你確定它在'User'類中嗎?編譯器似乎不同意。你可以發佈'User'類的代碼嗎? – Mizipzor 2012-08-15 10:32:16

+4

請更正這個問題的標題 – 2012-08-15 10:33:58

回答

4

你是不是叫你的getUser方法,但System.Security.Principal.IPrincipal之一。使用完整的命名空間。

List<User> results = MyNamespace.User.GetUser();