1
votes

i am trying to do is after the user register and they click yes it will go to LoginPage. or else the user click the "Cancel" it will go to registration, please help me guys.. i am newbee in xamarin

    void Handle_Clicked(object sender, System.EventArgs e)
    {
      string ConnectionString = "Server=10.0.2.2; Port=5432;User Id=postgres; Password=ncf123; Database=Accounting";
            try
            {
                NpgsqlConnection connection = new NpgsqlConnection(ConnectionString);
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("adi na");

            }
            NpgsqlConnection connections = new NpgsqlConnection(ConnectionString);
            connections.Open();
            NpgsqlCommand command = connections.CreateCommand();
            command.CommandText = "INSERT INTO account(username, password, email, phonenumber) VALUES ( '" + EntryUsername.Text + "', '" + EntryPassword.Text + "','" + EntrEmail.Text + "','" + EntryPhoneNumber.Text + "')";
            try
            {
                NpgsqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    EntryUsername.Text = reader[0].ToString();
                    EntryPassword.Text = reader[1].ToString();
                    EntrEmail.Text = reader[2].ToString();
                    EntryPhoneNumber.Text = reader[3].ToString();

                }
            connections.Close();
            Device.BeginInvokeOnMainThread(async () =>
            {
                var result = await DisplayAlert("Congratulations", "User Registration Successfull", "Yes", "Cancel");
                if (result)
                {
                    await Navigation.PushAsync(new LoginPage());
                }
                else
                {
                    await Navigation.PushAsync(new registration());
                }

            });

        }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

UPDATE this is my App.xaml.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new registration();
    }

    protected override void OnStart()
    {
    }

    protected override void OnSleep()
    {
    }

    protected override void OnResume()
    {
    }
}

Please help me guys, i am newbee in xamarin and postgresql

1
as the error says, you need to use a NavigationPage. You need to wrap the current page in a NavigationPage, most likely when you assign MainPage in App.xaml.cs - Jason
How mr @Jason ? - user12290120
MainPage = new NavigationPage(new WhateverMyMainPageIsCalled()); - Jason
why Mainpage? can i replace it with LoginPage? but i tried this one already and it doesnt work - user12290120

1 Answers

0
votes

in your app.cs change MainPage = new MainPage(); to MainPage = new NavigationPage(new MainPage()); Where MainPage() is the name of the page that you want to open when you start the app