GetUserDetails

| | |
public static string GetUserDetails(string stringInput, int displayoption)
          {
                if (stringInput == "")
                {
                    return strErrorMessage_GetUserDetails;
                }
                else
                {
                    string strUserName = "";
                    string strName = "";
                    string strReturnString = "";

                    string query1 = "SELECT user_name, first_name, last_name FROM users where user_id = '" + stringInput + "'";
                    //    strReturnString = "<p>" + query1 + "</p>";

                    using (SqlConnection conn1 = new SqlConnection(connString))
                    {
                        using (SqlCommand cmd1 = new SqlCommand(query1, conn1))
                        {
                            conn1.Open();
                            SqlDataReader rdr1 = cmd1.ExecuteReader();
                            if (rdr1.HasRows)
                            {
                                while (rdr1.Read())
                                {
                                    strUserName = rdr1["user_name"].ToString();
                                    strName = rdr1["first_name"].ToString() + " " + rdr1["last_name"].ToString();

                                    switch (displayoption)
                                    {
                                        case 1:
                                            strReturnString = strReturnString + strUserName;
                                            break;
                                        case 2:
                                            strReturnString = strReturnString + strName + " (" + strUserName + ")";
                                            break;
                                        default:
                                            strReturnString = strReturnString + strName + " (" + strUserName + " " + stringInput + ")";
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    return strReturnString;
                }
Originally Posted on February 21, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.