RAMESH SAHU

RAMESH SAHU

  • NA
  • 121
  • 12.6k

how to use login form user MDIParent form

Dec 6 2016 8:41 AM
 hi i m ramesh sahu i m develop on window application project in C#.Net i have taken MDIParent Form and menu bar Login Option i m unable to do logout ones login is active and how to do log out in mdiparent form 
i want to show username who login in mdiparent form either on title bar or toolstrip menu
please help me sir  
 
 
 
this is my code
 
private void LogIn_Btn_Click(object sender, EventArgs e)
{
if ((txtUId.Text != "") && (txtpwd.Text != ""))
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-ERCK15V;Initial Catalog=AnySoftDB;Integrated Security=True; User Id=sa; Password=123");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Login_Sp";
cmd.Parameters.AddWithValue("@UserId", this.txtUId.Text);
cmd.Parameters.AddWithValue("@Pwd", this.txtpwd.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.HasRows == true)
{
MessageBox.Show("Login Successfully Done");
this.MdiParent.Text = "Anyosoft " + " Welcome " + txtUId.Text;
Form fm = Application.OpenForms["Login"];
this.Visible = false;
}
}
if (dr.HasRows == false)
{ MessageBox.Show("Access Denied, password username mismatched"); }
}
else { MessageBox.Show("Enter username and password"); }
}
 

Answers (2)