I want to show the purchased courses for a user at 'Page Load Event' when user performed Login.
The conditions are :
- User has a unique email ID saved during SignUp
- When user purchased a course it is being saved w.r.t his email ID (could be multiple courses)
- Had multiple labels, but I want one course displayed on one label respectively
I have tried this code.
Table newadmission
:
pgenrolled | |
---|---|
testmail | Course 1 |
testmail | Course 2 |
testmail | Course 3 |
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(strcon);
try
{
if (Session["get"].Equals(""))
{
Label1.Text = "NIL Value";
}
else if (Session["get"].Equals("userinfolbl"))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
cmd = new SqlCommand("SELECT Distinct pgenrolled FROM newadmission WHERE email= '" + Session["em"].ToString() +"' ",cn);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Label1.Text = "You have purchased : 1. " + dr.GetValue(0).ToString(); // course 1 name
Label2.Text = "2. " + dr.GetValue(0).ToString(); // course 2 name
Label3.Text = "3. " + dr.GetValue(0).ToString(); // course 3 name
}
dr.Close();
}
cn.Close();
}
}
}
catch (Exception ex)
{
Response.Write("<script>alert('Exception Unhandled : user_courses_pg '+'" + ex.Message.ToString() + "') </script>");
}
}