You must Sign In to post a response.
  • Category: .NET

    How to create form which shows profile info of login user?

    Hey friends , i have 2 forms named "Login" and "MemberProfile" Login form have name and member_id as fields and login button also worked and after clicking login button "MemberProfile"
    form opens but i want to code for this form which shows information of login user based on member_id, that means it should retrieve this id from login form and use it in profile form to get values . and i want to assign all information values to labels of profile form.

    i.e. lable1 should get name value , lable2 =age value. and so on.

    thnaks for help.
  • #759441
    Hello Priyanka,

    You can achieve your task by using the below code:

    public string username;
    private void ButtonLogin_Click(object sender, EventArgs e)
    {
    //Do your validation code
    username = TextBoxUN.Text;
    this.Hide();
    MemberProfile mp = new MemberProfile();
    mp.ShowDialog();
    }

    private void MemberProfile_Load(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection("connectionstring");
    try
    {
    con.Open();
    Login lg = new Login();
    SqlCommand cmd = new SqlCommand("SELECT mp.MyName, mp.MyAge, mp.MyGender FROM MemberProfile AS mp INNER JOIN Login AS l ON mp.Username = l.Username WHERE mp.Username = '" + lg.username + "' ", con);
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    dr.Read();
    label1.Text = dr["MyName"].ToString();
    label2.Text = dr["MyAge"].ToString();
    label3.Text = dr["MyGender"].ToString();
    dr.Close();
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    finally
    {
    con.Close();
    }
    }

    Hope this will help you to solve your query.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #759446
    once the user logs on in the login page, store the userid in the session variable and in the MemberProfile page using this session id retrieve all the information of the logged in user from the database stored procedure and display it in the respective fields in the MemberProfile page. As sessions are unique to each user, each user will have their own details displayed on this page.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #759452
    Hi

    Try below logic


    private void ButtonLogin_Click(object sender,
    EventArgs e)
    {
    class obj=new class();
    obj.Name=txtname.Text;
    obj.Age=txtage.Text;
    obj.Mobile=txtmob.Text;

    if(obj.checkMember())
    {
    Session[ "SessionName" ]=obj.Name;
    Session["SessionAge"]=obj.Age;
    Session["SessionMob"]=obj.Mobile;
    }
    }
    Label1.Text=SessionName;
    Label2.Text=SessionAge;
    Label3.Text=SessionMob;


    Regards.

    Sridhar Thota.
    DNS Member.
    "Hope for the best..Prepare for the worst.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #761920
    Hi

    You can try this code


    private void button2_Click(object sender, EventArgs e)
    {
    sqlcon.Open();
    DataTable dt = new System.Data.DataTable();
    SqlDataAdapter sqladp = new SqlDataAdapter("Select * from members order by id=1", sqlcon);
    sqladp.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    label1.Text = dt.DefaultView[0]["Name"].ToString();
    label2.Text = dt.DefaultView[0]["Age"].ToString();
    }
    }

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments