我有一个名为Users
in SQL服务器的表,它保留了password
,email
和UserID
这是主键。然后在我的项目中我有两个表单,第一个表单获取密码和用户名称,然后如果输入密码和电子邮件存在于表中它连接到第二个表单,如果不是,它不连接。然后连接到银行我正在使用实体框架。这是我的连接字符串:
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();
}
我知道我必须使用UserID
作为主键但我不知道如何写UserID
to获取所有行?现在它只是得到row2
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();
}