예제 #1
0
        public List<Friend> GetFriends(string userId)
        {
            SqlDataReader myReader = null;
            List<Friend> tmpfriendList = new List<Friend>();

            try
            {
                command.Connection = myConnection;
                myConnection.ConnectionString = connectionString;
                myConnection.Open();

                command.CommandText = "sp_GetFriends";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Clear();

                command.Parameters.Add("@UserID", System.Data.SqlDbType.NVarChar, 128);

                command.Parameters["@UserID"].Value = userId;

                myReader = command.ExecuteReader();

                if (myReader != null)
                {
                    var tmpFriend = new Friend();

                    while (myReader.Read())
                    {
                        tmpFriend = new Friend();
                        tmpFriend.Username = myReader[0].ToString();
                        tmpFriend.FriendId = myReader[1].ToString();

                        tmpfriendList.Add(tmpFriend);
                    }
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (myReader != null)
                {
                    myReader.Close();
                }
                if (myConnection != null)
                {
                    myConnection.Close();
                }
            }
            return tmpfriendList;
        }
예제 #2
0
        public List<Friend> FindUser(string userName)
        {
            SqlDataReader myReader = null;
            List<Friend> userList = new List<Friend>();
            try
            {
                command.Connection = myConnection;
                myConnection.ConnectionString = connectionString;
                myConnection.Open();

                command.CommandText = "sp_SearchUser";
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.Clear();

                command.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 255);

                command.Parameters["@UserName"].Value = userName;

                myReader = command.ExecuteReader();

                while (myReader.Read())
                {
                    Friend myFriend = new Friend();
                    myFriend.Username = myReader[0].ToString();
                    myFriend.FriendId = myReader[1].ToString();

                    userList.Add(myFriend);
                }

            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (myReader != null)
                {
                    myReader.Close();
                }
                if (myConnection != null)
                {
                    myConnection.Close();
                }
            }

            return userList;
        }