Dropdownlist与数据库绑定
1、Dropdownlist与数据库绑定。
string sql_subject="select subject from
tt_subject";
OleDbConnection Conn=db.okConn();
Conn.Open();
OleDbCommand cmd = new OleDbCommand(sql_subject,
Conn); //这里从数据库中读入到Dropdownlist
OleDbDataReader reader =
cmd.ExecuteReader();
Dropdownlist9.DataSource =
reader;
Dropdownlist9 .DataTextField
="subject";//字段
Dropdownlist9.DataValueField =
"subject";
Dropdownlist9 .DataBind ();