-1

i try to connect with my MySql connection in a other .cs file but i cant reach the connection string con which is located in the MySQL.cs here is the code i am using:

MainPage.cs

Data_Layer.MySQL mm = new Data_Layer.MySQL();

        private async void LoginKlik(object sender, EventArgs e)
        {

            try
            {
              mm.con.Open();
            }
         catch
         {}
         finally
         {}

I am getting a red line under the line mm.con.Open(); with the statement inaccisebale due protection level

MySQL.cs

namespace VerlofXamarin.Data_Layer
{
    public class MySQL
    { 
            MySqlConnection con = new MySqlConnection("Server=arabig.nl;Port=3306;database=arabignl_project;User Id=arabignl_project;Password=JariR0800;charset=utf8");
    }
}

2 Answers2

1

As Sebastian Hofmann pointed c# declares fields as private by default. Like MySqlConnection con doesn't have a modifier is private, change it to public and will be accecible.

public MySqlConnection con = new MySqlConnection("Server=arabig.nl;Port=3306;database=arabignl_project;User Id=arabignl_project;Password=JariR0800;charset=utf8");

An extended explanation about this here

More info of access modifiers

0

This should do the trick:

public MySqlConnection con = new MySqlConnection("Server=arabig.nl;Port=3306;database=arabignl_project;User Id=arabignl_project;Password=JariR0800;charset=utf8");
Jose
  • 71
  • 3