- Ask user for username and password
- On click button it checks the database connected for this username and password,
- When correct it stores it's ID number in a variable, by default this variable is 0.
- Then I run a If-statement, if the ID is >= 0, it needs to open another form. if not it displays Error message.
MessageBox in first If case displays the correct ID (1,2,3 whatever) Now then on Form3, just a simple textbox1.text = "hi"; gives me the error:
Object reference not set to an instance of an object c#. and it displays the textbox line.
int IDnumber = 0;
SqlCommand dataCommand = new SqlCommand(" SELECT ID FROM leden WHERE [Username]='" + username_txt.Text + "' and [Password]='" + password_txt.Text + "'", SC);
SC.Open();
IDnumber = Convert.ToInt32(dataCommand.ExecuteScalar());
SC.Close();
if (IDnumber >= 1)
{
MessageBox.Show("Logged in, welcome ID number:" + IDnumber, "test");
Form3 f3 = new Form3(IDnumber);
f3.Show();
}
else
{
MessageBox.Show("Wrong Username and/or Password");
}
}
form3:
public Form3(int _IDnumber)
{
int IDnumber = _IDnumber;
textBox1.Text = "hi";
}
Of course the textbox is a test, to show that it doesn't matter what textbox I use, it just gives me this error. Yes, I do still use unecrypted passwords, don't know how to do that yet