我是新来的c#和精简版。我编写了一个模拟登录过程的简单控制台应用程序。我试图用参数来使用dapper查询登录表。即使用户和密码是正确的,我仍然无法通过。我会感谢任何方向来完成成功的登录测试。用短小精灵查询登录表
public class Login
{
public string UserName { get; set; }
public string Password { get; set; }
public Login()
{
}
public Login(string username, string password)
{
UserName = username;
Password = password;
}
}
public static class Helper
{
public static string Con(string name)
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
}
public class DataAccess
{
public List<Login> GetLogin(string username, string password)
{
using (IDbConnection connection = new SqlConnection(Helper.Con("Stock")))
{
var output = connection.Query<Login>("sp_GetLogin @UserName, @Password", new { UserName = username, Password = password }, commandType:CommandType.Text).ToList();
return output;
}
}
}
static void Main(string[] args)
{
string txtusername;
string txtpassword;
Console.WriteLine("Enter your Username:");
txtusername = Console.ReadLine();
Console.WriteLine("Enter your Password:");
txtpassword = Console.ReadLine();
Console.WriteLine("Username typed: {0}, Password typed: {1}", txtusername, txtpassword);
Login login = new Login();
DataAccess obj = new DataAccess();
obj.GetLogin(txtusername, txtpassword);
if (obj != null)
{
if (login.Password == txtpassword)
{
Console.WriteLine("User credentials successfull");
}
else Console.WriteLine("Password don't match");
}
else Console.WriteLine("Username don't match");
Console.ReadLine();
}
我做过调试。我得到它运行 – mauricio