title: Displaying user's name in LoginView
body: <p>The default website template when creating an ASP.NET project in Visual Studio shows the user's username when logged in in the LoginView. I would like to replace this with the user's first name. I have this stored in a database, so in the Site.master page I tried the following (in the page onload):</p>
  
  <pre><code>    MembershipUser user = Membership.GetUser();
      string id = user.ProviderUserKey.ToString();
         SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
          try
          {
              using (connection)
              {
                  using (SqlCommand con_get = new SqlCommand("SELECT firstname FROM x WHERE userId='" + id + "'", connection)) //Executes SQL command             
                  {
                      try
                      {
                          connection.Open(); //Opens the database connection
                          using (SqlDataReader reader = con_get.ExecuteReader())
                          {
                              if (reader != null)
                              {
                                  while (reader.Read())
                                  {
                                      Label label1 = (Label)sender;
                                      label1.Text = reader["x"].ToString();
                                  }
                              }
                          }
                      }
                      catch
                      {
  
                      }
  
                      finally
                      {
                          connection.Close(); //Closes the database connection
                      }
                  }
              }
          }
          catch
          {
  
          }
  </code></pre>
  
  <p>This does not work at the moment. I also tried not using the sender and just tried to use label1.Text = reader["x"].ToString(); but that did not work.</p>
  
  <p>Does anyone have any suggestions about how I can make this work?</p>
  
  <p>Also, is this the correct approach? Surely there is a more efficient way to load the first name and not reload this every time the user navigates to a different page (therefore reducing the # of queries against the database)?</p>