프로그래밍/ASP.NET

ASP.NET - Split() - 콤마로 구별된 개별상품 코드로 개별상품 명 반환

Doonee 2013. 10. 16. 12:00
반응형

     #region GetName() : 개별상품 코드로 개별상품 명 반환
    /// <summary>
    /// 개별상품 코드로 개별상품 명 반환
    /// </summary>
    /// <param name="codes">코드들</param>
    /// <returns></returns>
    protected string GetName(string codes)
    {
        string strValue = string.Empty;
        string strSql = string.Empty;
        string strSelValue = string.Empty;
        string[] arrSel = codes.Split(new char[] { ',' });

        for (int i = 0; i < arrSel.Length; i++)
        {
            //검색쿼리
            strSelValue = string.Empty;
            strSql = String.Format(@"SELECT 상품명 FROM 테이블명 WHERE 코드 = '{0}'", arrSel[i]);            
            strSelValue = (string)(DatabaseFactory.CreateDatabase("ConnectionString").ExecuteScalar(CommandType.Text, strSql));
            if (!String.IsNullOrEmpty(strSelValue))
            {
                strValue += strSelValue + ",";
            }
        }

        return strValue;
    }
    #endregion