I am trying to create a login system for a uwp(winui3) app. In the login window the user enters his credentials and on clicking the login button he/she is redirected to mainwindow. But I get an Unhandled exception error.
App.xaml.cs
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
loginpage=new LoginWindow();
loginpage.Activate();}
LoginWindow.xaml.cs
private void Login_Click(object sender, RoutedEventArgs e)
{
string query = "select * from ***** where username='" + username.Text + "' and password='" + password.Text + "'";
DataTable dt = new DataTable();
dt = Tools.getdatafromDATABASE(query);
if (dt.Rows.Count == 0)
{
//Display incorrect username and password message
}
else
{
//Redirect to MainWindow
Window mainwindow = new MainWindow();
mainwindow.Activate();
}
}
}
MainWindow.cs
public MainWindow()
{
this.InitializeComponent();
MainContent.Navigate(typeof(HomePage));
}