private void button7_Click(object sender, EventArgs e)
{
var login = from p in User
where p.UserName == UserName.Text
&& p.UserPwd == Password.Text
select p; if(login.Count()>0)
{
foreach(var item in login)
{
if(item.Admin==1)
{
//转到指定页面
}
else
{
//不是管理员
}
}
}
}
public class User
{
public int ID { get; set; }
public int UserName { get; set; }
public int UserPwd { get; set; }
public int Admin { get; set; }
}
写的不好讲究着看吧。
{
var login = from p in User
where p.UserName == UserName.Text
&& p.UserPwd == Password.Text
select p; if(login.Count()>0)
{
foreach(var item in login)
{
if(item.Admin==1)
{
//转到指定页面
}
else
{
//不是管理员
}
}
}
}
public class User
{
public int ID { get; set; }
public int UserName { get; set; }
public int UserPwd { get; set; }
public int Admin { get; set; }
}
写的不好讲究着看吧。
&& p.UserPwd == Password.Text select new User
{
Admin =p.Admin
}).ToList<User>();
//另外一种写法。db.User 是你的数据库。你新建一个linq to sql 类 DataUser.dbml
连上数据库然后把User表拖到里面就可以 用了
protected void LoginButton_Click(object sender, EventArgs e)
{
DataClassesDataContext dc = new DataClassesDataContext();
List<JJUser> a = (from p in dc.JJUser
where p.UserName == UserName.Text
&& p.UserPwd == Password.Text
select new JJUser
{
AdminID = p.AdminID
}).ToList<JJUser>();
if (a.Count() > 0)
{
foreach (var item in a)
{
if (item.AdminID == 1)
{
Response.Write("<script>alert('*_-您是管理员-_*');location='#'</script>");
}
else
{
Response.Write("<script>alert('*_-您不是管理员-_*');location='#.aspx'</script>");
//不是管理员
}
}:“/Goods2619”应用程序中的服务器错误。
--------------------------------------------------------------------------------
不允许在查询中显式构造实体类型“JJUser”。 哪里错了啊~大侠
http://kb.cnblogs.com/page/70851/
http://msdn.microsoft.com/zh-cn/dd408820
=>改成下面的
List<JJUser> a = (from p in dc.JJUser
where p.UserName == UserName.Text
&& p.UserPwd == Password.Text
select p).ToList<JJUser>();