How to pass value entered by User while login to another form without having System.NullReferenceException ERROR ??
I'm Using a Class to help in passing the value from one form to another, the class code is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentFollowUp
{
public class Student
{
public string username { get; set; }
public string password { get; set; }
}
}
and then i made a login page where the user can enter his username and password and i made the connection with the database and when i run the code below i get this sentence :"An unhandled exception of type 'System.NullReferenceException' occurred in StudentFollowUp.exe
Additional information: Object reference not set to an instance of an object."
Here is the code and thank in advance :
private void loginlable_click(object sender, EventArgs e)
{
using (SqlConnection Connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\StudentFollowup.mdf;Integrated Security=True;"))
{
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From Users Where Username = '" + username.Text + "' and Password = '" + password.Text + "'", Connection);
DataTable dt = new DataTable();
StudentInfo.username = username.Text;
StudentInfo.password = password.Text;
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Main ss = new Main();
ss.Show();
}
else
{
MessageBox.Show("Please Check Your Username and Password");
}
}
}