This question already has an answer here:
I am trying to pass a username into a label in a windows form application from a login however it says Object reference not set to an instance of an object
in lblWelcome it says null but in the string msg it says the right logged in username why is this happening?
login:
i initialize it in the public part of the login
string msg;
then this is the if ssuccessul login
int i = ds.Tables[0].Rows.Count;
if (i == 1)
{
msg = "Welcome " + txtUsername.Text;
this.Hide();
Welcome f2 = new Welcome(msg);
f2.Show();
ds.Clear();
}
formwelcome
public Welcome()
{
InitializeComponent();
}
public Welcome(string msg)
{
InitializeComponent();
lblWelcome.Text = msg;
}
Aucun commentaire:
Enregistrer un commentaire