티스토리 뷰

💼 정보 ver1.0

ParameterDirection 열거형

James Wetzel 2009. 3. 17. 15:02
728x90
반응형

시나리오

DataSet을 기준으로 하는 쿼리 내의 상대 매개 변수의 형식을 지정합니다.

네임스페이스:  System.Data
어셈블리:  System.Data(System.Data.dll)
정보
internal DataSet getBoardList(ref BoardVariable.BoardList variable)
        {
            int startRecode = (variable.currentPage - 1) * variable.pageSize;
            int topCount = variable.currentPage * variable.pageSize;

            SqlConnection conn = new SqlConnection(DBconnectionString);
            SqlCommand comm = new SqlCommand("getBoardList", conn);


            comm.CommandType = CommandType.StoredProcedure;
            comm.Parameters.Add("@BoardID", SqlDbType.VarChar, 12).Value = variable.boardID;
            comm.Parameters.Add("@SearchOption", SqlDbType.VarChar, 10).Value = variable.searchOption;
            comm.Parameters.Add("@SearchKey", SqlDbType.VarChar, 30).Value = variable.searchKey;
            comm.Parameters.Add("@TopCount", SqlDbType.VarChar, 12).Value = topCount.ToString();
            comm.Parameters.Add("@Query", SqlDbType.VarChar, 200).Direction = ParameterDirection.Output;

            SqlDataAdapter adapter = new SqlDataAdapter(comm);
            DataSet ds = new DataSet();

            try
            {
                adapter.Fill(ds, startRecode, variable.pageSize, "BoardList");

throw new Exeception(comm.Parameter["@Query"].Value.ToString());
                return ds;                
            }
            catch (Exception e)
            {
                throw e;
            }
        }
비고
[DBMS]
ALTER PROCEDURE getBoardList
    @BoardID varchar(12),
    @SearchOption varchar(10),
    @SearchKey varchar(30),
    @TopCount varchar(12),
    @Query varchar(200) output
AS
    DECLARE @QuerySentence varchar(512)
   
    -- 검색 정보가 없는 경우
    IF(@SearchKey = '검색어')
        SET @QuerySentence = 'Select TOP '+@TopCount+' BoardList.*'+       
                                ' From BoardList'+
                                ' Where BoardID = '+char(39)+@BoardID+char(39)+
                                ' ORDER BY GroupID DESC, GroupStep ASC'
    -- '제목'이나 '작성자'로 검색하는 경우
    ELSE IF(@SearchOption = 'Subject' OR @SearchOption = 'Writer')
        SET @QuerySentence = 'Select TOP '+@TopCount+' BoardList.*'+
                                ' From BoardList'+
                                ' Where BoardID = '+char(39)+@BoardID+char(39)+
                                ' AND '+@SearchOption+' LIKE '+char(39)+'%'+@SearchKey+'%'+char(39)+                               
                                ' ORDER BY GroupID DESC, GroupStep ASC'   
    -- '본문 내용으로 검색하는 경우'
    ELSE IF(@SearchOption = 'Content')
        SET @QuerySentence = 'Select TOP '+@TopCount+' BoardList.*'+
                                ' From BoardList inner join BoardContent'+
                                ' on BoardContent.BoardID = '+char(39)+@BoardID+char(39)+
                                ' and BoardContent.BoardID = BoardList.BoardID'+
                                ' and BoardContent.GroupID = BoardList.GroupID'+
                                ' and BoardContent.GroupStep = BoardList.GroupStep'+                               
                                ' where BoardContent.Content LIKE '+char(39)+'%'+@SearchKey+'%'+char(39)+
                                ' ORDER BY BoardContent.GroupID DESC, BoardContent.GroupStep ASC'   
    EXEC(@QuerySentence)
    Set @Query = @QuerySentence                            




728x90
반응형