I have a registration form, a login form and a Main form.The program start with registration form. If i sign up the datas(name, email, password) load up to the local database. When i log in correctly show the main form. The main form has a usercontrol with a label. I would like to write a welcome text to the label with her/his name. Example: "Welcome Josh!". So I should to identify the user, so i use the textboxEmail.Text from the login form. My solution is not working. There is my code:
namespace personalFinance
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
var MainForm = new MainForm();
MainForm.Show();
HomepageUC hp = new HomepageUC(textboxEmail.Text);
hp.Show();
}
}
}
namespace personalFinance
{
public partial class HomepageUC : UserControl
{
string login = "";
public HomepageUC(string email)
{
InitializeComponent();
login = email;
var conn = new SqlConnection(@"Server=(localdb)\MSSQLLocalDB;
AttachDbFileName=|DataDirectory|database.mdf;");
conn.Open();
var cmd = new SqlCommand($"SELECT email FROM registration_data
WHERE email = '{login}'", conn);
var reader = cmd.ExecuteReader();
while (reader.Read()) labelWelcome.Text = reader[0].ToString();
}
}
}
I got that error: There is no argument given that corresponds to the required formal parameter 'email' of 'HomepageUC.HomepageUC(string)' personalFinance C:\Users\nickname18\source\repos\personalFinance\personalFinance\MainForm.Designer.cs
when i click this error retrieve to MainForm.Designer.cs this.HompageUC1 = new personalFinance.Homepage1(); it is underline with red.