the syntax : Class1: public void btnLogin_Click(object sender, RoutedEventArgs e) { if (isValid()) { SqlCommand cmd = new SqlCommand("SELECT COUNT(1) FROM usertb WHERE username=@username AND pass_word=@pass_word", con); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@username", txtUser.Text); cmd.Parameters.AddWithValue("@pass_word", txtPass.Password); con.Open(); int count = Convert.ToInt32(cmd.ExecuteScalar()); SqlCommand cmd1 = new SqlCommand("SELECT usr_id ,userType FROM usertb WHERE username=@username AND pass_word=@pass_word", con); cmd1.CommandType = System.Data.CommandType.Text; cmd1.Parameters.AddWithValue("@username", txtUser.Text); cmd1.Parameters.AddWithValue("@pass_word", txtPass.Password); SqlDataReader reader1; reader1 = cmd1.ExecuteReader(); string userType = ""; string y1 = "1"; if (reader1.Read()) { string userID = reader1["usr_id"].ToString(); string v = reader1["userType"].ToString(); value = y; userType = v; } CurriculumControl curriculumControl = new CurriculumControl(); curriculumControl.SetUserId(y1); con.Close(); if (count == 1 && userType == "Admin") { MainInterface dashboard = new MainInterface(); LoginView loginView = new LoginView(); dashboard.Show(); this.Visibility = Visibility.Collapsed; CurriculumControl passID = new CurriculumControl(); } else { MessageBox.Show("Username or password is incorrect"); } //cmd.ExecuteNonQuery(); Console.WriteLine(count); } } i plan the userID to get stored in a variable in another class but the output is always null in the second class userID has value but when i pass it in another class it becomes null