[英]checking contents of a table in SQL server by Entity Framework
I have a table named Users
in SQL server which retains password
, email
and UserID
which is the primary key. 我在SQL Server中有一个名为Users
的表,其中保留了password
, email
和作为主键的UserID
。 Then in my project I have two forms,first form gets password and name of users and then if entered password and email exist in the table it connects to second form and if not it does not. 然后在我的项目中,我有两种形式,第一种形式获取密码和用户名,然后如果表中存在输入的密码和电子邮件,它将连接到第二种形式,如果没有,则不会。 then to connect to bank I am using Entity Framework. 然后连接到银行,我正在使用实体框架。 this is my connection string: 这是我的连接字符串:
int UserID = 2;
UsersEntities db = new UsersEntities();
var find = db.CalUsers.Find(UserID);
if (find.Email == txtEmail.Text && find.Password == txtPassword.Text)
{
SmallCalculator example = new SmallCalculator();
example.ShowDialog();
}
I know I must use UserID
as primary key but I dont know how to write UserID
to get all rows?now it just gets row 2
我知道我必须使用UserID
作为主键,但是我不知道如何编写UserID
来获取所有行?现在它只获取第2
行
int UserID = 2; // you don't actually know this value since user is not giving it to you
UsersEntities db = new UsersEntities();
//hopefully email address has a unique constraint:
var find = db.CalUsers.FirstOrDefault(x=>x.Email == txtEmail.Text.Trim());
if(find == null) return; //do something else
if (find.Email == txtEmail.Text && find.Password == txtPassword.Text)
{
SmallCalculator example = new SmallCalculator();
example.ShowDialog();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.