I have two files. Need to get variables from one to another. I set them as global in the file where they are defined and filled. But in the second file when it reads variables, they are empty. How can I solve this problem? The code from the first file:
public sealed partial class NewOrder : Page
{
public string Name1;
public string Mob;
public string Adres;
public string Email;
public string telephone;
public NewOrder()
{
searchButton.Click += async delegate
{
telephone = searchtext.Text;
using (MySqlConnection connection = new MySqlConnection("...."))
{
connection.Open();
MySqlCommand createCommand = new MySqlCommand(
"SELECT * FROM customers WHERE mob LIKE N'" + telephone + "'", connection);
EncodingProvider ppp;
ppp = CodePagesEncodingProvider.Instance;
System.Text.Encoding.RegisterProvider(ppp);
MySqlDataReader reader = createCommand.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Name1 = reader.GetString(1);
Mob = reader.GetString(2);
Adres = reader.GetString(3);
Email = reader.GetString(4);
}
}
}
}
}
}
The code from the second file:
public sealed partial class Details : Page
{
public Details()
{
this.InitializeComponent();
NewOrder A = new NewOrder();
name.Text = A.Name1;
tel.Text = A.Mob;
adres.Text = A.Adres;
email.Text = A.Email;
}
}
That what I see.
The exception is here: name.Text = A.Name1;
An exception of type 'System.ArgumentNullException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: Value cannot be null.