I have a sign in method, which gets the details of a user based on the password and email that they enter. Within this method i call a function which stores those details inside of a list.
To confirm that these details have been saved I've then used MessageBox.Show(userDetails[0].ToString()) to display the first value. however I'm just getting the name of the class :
Below is the code for the sign in method:
public static List<CustomerLogin> userDetails = new List<CustomerLogin>();
private void SignInButton_Click(object sender, EventArgs e)
{
string query = "SELECT c.customerId, c.firstname, c.lastname, c.address, c.contactNumber, cl.email, cl.password FROM customer c Join customerLogin cl ON cl.customerId = c.customerId where cl.email =@email AND cl.password=@password";
cmd = new SqlCommand(query, _IsqlDataFunctions.GetConnection());
cmd.Parameters.AddWithValue("@email", signInEmail.Text);
cmd.Parameters.AddWithValue("@password", SqlDataFunctions.hashPassword(signInPassword.Text));
_IsqlDataFunctions.GetCustomerLogin(cmd, userDetails);
_IsqlDataFunctions.Login(cmd, new SignIn(), new Dashboard());
MessageBox.Show(userDetails[0].ToString());
}
This is the code i have within the CustomerLogin class:
{
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string ContactNumber { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
Finally this is the GetCustomerLogin function that im calling within the SignInButton_Click method
public void GetCustomerLogin(SqlCommand cmd, List<CustomerLogin> userDetails)
{
try
{
connection.Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
userDetails.Add(new CustomerLogin()
{
CustomerId = reader.GetInt32(0),
FirstName = reader.GetString(1),
LastName = reader.GetString(2),
Address = reader.GetString(3),
ContactNumber = reader.GetString(4),
Email = reader.GetString(5),
Password = reader.GetString(6),
});
}
}
catch (System.NullReferenceException )
{
MessageBox.Show("Your login credentials are incorrect");
}
connection.Close();
}
Can someone please tell me what im doing wrong here? Thankyou!
EDIT: ive noticed that I might be calling the attributes of the customerLogin the wrong way i.e userdetails[0]. What would be the correct way to do this?