Inter-Class Communication

Mar 19 2010 5:02 PM
Hello folks,

I am having a problem in my program that has apparently no reason to show itself but somehow it is. It actually comes when i run the program using F5 key, the program doesn't work properly while I execute it step by step using F11 key, it works perfectly fine.

Well, here is my problem.

frm_Login obj = new frm_Login();
username = obj.getUsername();
lbl_Welcome.Text = "Welcome "+username;


This given code is placed in another class but when i call it doesn't work.
The code of the function getUsername() is as given below

public string getUsername()
        {
            SqlConnection con = new SqlConnection(Properties.Settings.Default.ConnectionStr);
            string getCurrentUsername = "select User_Name from tblSecUsers where User_ID = '"+tbx_UserID.Text+"'";
            con.Open();
            SqlCommand cmd = new SqlCommand(getCurrentUsername, con);
            SqlDataReader reader = null;
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                username = reader["User_Name"].ToString();           
            }
                      
            con.Close();
            return username;
        }


Urgent help required fellows.

Regards.

Answers (8)