블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 9. 28. 15:24 .Net Project/ADO.NET 3.5
반응형

 RowFilter : 데이터 검색시 사용하는 속성 : "CategoryName" Like '%컴퓨터%'"
        Connection -> Command -> DataAdapter -> DataSet ->
        DataTable -> DataView -> DataView.RowFilter 속성

DataView에 표시할 행을 필터링하는 데 사용하는 식을 가져오거나 설정


using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class Category_FrmRowfilter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //커넥션
        SqlConnection con = new SqlConnection
                          (ConfigurationManager.ConnectionStrings
                           ["ConnectionString"].ConnectionString);
        con.Open();

        //커멘드
        SqlCommand cmd = new SqlCommand
                    ("Select *From Categories", con);
       
        cmd.CommandType = CommandType.Text;

        //어댑터
        SqlDataAdapter da = new SqlDataAdapter(cmd); //초기화
        DataSet ds = new DataSet();
        da.Fill(ds, "Categories");

        //전체출력
        this.ctlSearchList.DataSource = ds;
        this.ctlSearchList.DataBind();
        
        con.Close();
      
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection
                     (ConfigurationManager.ConnectionStrings
                      ["ConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand
                   ("Select *From Categories", con);
        cmd.CommandType = CommandType.Text;

        SqlDataAdapter da = new SqlDataAdapter(cmd); //초기화
        DataSet ds = new DataSet();
        da.Fill(ds, "Categories");

        //전체출력 
        this.ctlSearchList.DataSource = ds;
        this.ctlSearchList.DataBind();

       
        //[1]DataTable변환
        DataTable dt = ds.Tables[0];

        //[2]DataView 변환
        DataView dv = dt.DefaultView;

        //[3]DataView.RowFilter변경
        dv.RowFilter = "CategoryName Like '%" + txtSerchquery.Text + "%'";
        dv.Sort = "CategoryName Asc"; //정렬

        this.ctlSearchList.DataSource = dv;
        this.ctlSearchList.DataBind();
       
        con.Close();
   }
}






반응형
posted by Magic_kit