아래는 addrbook 이라는 테이블의 tel, name 컬럼중...
text에 name, value에 tel을 매핑 시키는 예 입니다.
(DataAdapter를 사용하지 않았습니다.)
private void Page_Load(object sender, System.EventArgs e)
{
string ConStr = ("server=(local);uid=sa;pwd=pass;database=pubs");
SqlConnection Conn = new SqlConnection(ConStr);
Conn.Open();
string sql = "select name, tel from addrbook ";
SqlCommand myCommand = new SqlCommand(sql, Conn);
SqlDataReader myReader = myCommand.ExecuteReader();
int i=0;
DropDownList1.DataSource = myReader;
DropDownList1.DataValueField = "tel";
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}



댓글 없음:
댓글 쓰기