Вот пример на WPF. Надеюсь, что ход мыслей будет понятен
MySqlConnection con = new MySqlConnection(@"host=localhost; port = your.PORT;User id = root; password = 'your.PASS'; SslMode = true; Database ='your.DATABASE'");
public int I;
private void Login_Click(object sender, RoutedEventArgs e)
{
I = 0;
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from user where username = '"+username.Text+"'and pass= '"+PasswordBox.Password+"'";
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
I = Convert.ToInt32(dt.Rows.Count.ToString());
if (I == 0)
{
//Выдать ошибку
}
else
{
this.Hide();
MainPage mp = new MainPage();
mp.Show();
}
con.Close();
}