I've got another issue. My method:
public StudentProfile GetFullStudentProfile(int userID)
{
SqlConnection conn = new SqlConnection(Config.DbConnectionString);
SqlCommand cmd = new SqlCommand("GetFullUserProfile", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int));
cmd.Parameters["@UserID"].Value = userID;
StudentProfile sp = null;
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
if (reader.Read())
{
sp = new StudentProfile((int)reader["UserID"], (string)reader["UserName"], (string)reader["UserFamilyName"], (DateTime)reader["UserBirthDay"], (string)reader["UserTelephone"], (string)reader["UserEmail"], (DateTime)reader["UserRegDate"], (string)reader["UserComment"], (bool)reader["UserActive"]);
}
reader.Close();
}
catch (Exception ex)
{
//lbl.Text = ex.Message;
}
finally
{
conn.Close();
}
return sp;
}
Code in WebUserControl:
protected void ddlStudents_SelectedIndexChanged(object sender, EventArgs e)
{
CatalogAccess ca=new CatalogAccess();
lblEmail.Visible = true;
lblName.Visible = true;
lblTelephone.Visible = true;
HiddenID.Value = ddlStudents.SelectedValue;
lblName.Text = HiddenID.Value;
lblEmail.Text = ca.GetFullStudentProfile(ddlStudents.SelectedIndex).UserEmail;
lblFamilyName.Visible = true;
lblBirth.Visible = true;
ddlStudents.Items.Clear();
PopulateStudentsDDL();
}
When I run the code I am getting exception

Do I understand right that the problem is in method GetFullStudentProfile()? If it's so, how can it be fixed?
I think the problem is:
StudentProfile sp = null;
So it says that variable sp was not filled with data in try block. Is it?
Now adding the StudentProfile.cs class listing:
public class StudentProfile
{ public StudentProfile(int userID, string userName, string userFamilyName, DateTime userBirthDay, string userTelephone, string userEmail,DateTime userRegDate,string userComment,bool userActive) { UserID = userID; UserName = userName; UserFamilyName = userFamilyName; UserBirthDay = userBirthDay; UserTelephone = userTelephone; UserEmail = userEmail; UserRegdate = userRegDate; UserComment = userComment; UserActive = userActive; }
public int UserID
{
get;
set;
}
public string UserName
{
get;
set;
}
public string UserFamilyName
{
get;
set;
}
public DateTime UserBirthDay
{
get;
set;
}
public string UserTelephone
{
get;
set;
}
public string UserEmail
{
get;
set;
}
public DateTime UserRegdate
{
get;
set;
}
public string UserComment
{
get;
set;
}
public bool UserActive
{
get;
set;
}
}