I am trying to figure out how to create a basic login system using UWP and MSSQL but I can't seem to figure it out. I used the Microsoft website to find the information on how to connect a database to UWP but the problem is when I want to test the login condition. NOTE: This is just for me trying to figure it out. I am still a student.
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)
{
}
}
}
Here is my class:
public class UsersLogin: INotifyPropertyChanged
{
public string username { get; set; }
public string password { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
The problem is, that it cant find the username or password properties from the class. Can someone help?