我有一个错误说我没有一个名为'GetUser'的方法,即使它在那里。错误说:“System.Security.Principal.IPrincipal'不包含'GetUser'的定义并且没有扩展方法可以找到接受“System.Security.Principal.IPrincipal”类型的第一个参数的“GetUser”“
这是我在用户类中的代码
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():
表示没有方法。
我如何在visual studios C#中解决这个问题请帮助谢谢