C# 需要帮助为UWP创建登录系统吗
我试图弄明白如何使用UWP和MSSQL创建一个基本的登录系统,但我似乎弄不明白。 我使用Microsoft网站查找有关如何将数据库连接到UWP的信息,但问题是何时需要测试登录条件。 注意:这只是我想弄明白的。我还是个学生C# 需要帮助为UWP创建登录系统吗,c#,sql,sql-server,uwp,C#,Sql,Sql Server,Uwp,我试图弄明白如何使用UWP和MSSQL创建一个基本的登录系统,但我似乎弄不明白。 我使用Microsoft网站查找有关如何将数据库连接到UWP的信息,但问题是何时需要测试登录条件。 注意:这只是我想弄明白的。我还是个学生 public MainPage() { this.InitializeComponent(); } public string ConnectionString { get; set; } = @"Data Source =.; In
public MainPage()
{
this.InitializeComponent();
}
public string ConnectionString { get; set; } = @"Data Source =.; Initial Catalog = LoginTest; Integrated Security = True";
private void Button_Click(object sender, RoutedEventArgs e)
{
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
}
public ObservableCollection<UsersLogin> GetProducts(string connectionString)
{
const string GetProductsQuery = "select username, password, from Products";
var products = new ObservableCollection<UsersLogin>();
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = GetProductsQuery;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (username == UsernameText.Text() && password == PasswordText.Text())
{
Frame.Navigate(typeof(page));
}
}
}
}
}
}
return products;
}
catch(Exception ex)
{
}
}
}
问题是,它无法从类中找到用户名或密码属性。有人能帮忙吗 我认为您需要从
读取器
对象获取值
while (reader.Read())
{
if (reader[0].ToString() == UsernameText.Text() && reader[1].ToString() == PasswordText.Text())
{
Frame.Navigate(typeof(page));
}
}
或者,您可以先将这些值读入用户名/密码,然后进行比较,如下所示:
UsersLogin userLogin = new UsersLogin();
userLogin.username = reader[0].ToString();
userLogin.password = reader[1].ToString();
此外,您可能希望查看我将如何读取值的可能重复项?很抱歉问。第一次用UWP做登录页面
UsersLogin userLogin = new UsersLogin();
userLogin.username = reader[0].ToString();
userLogin.password = reader[1].ToString();