1
string
sql
=
"
SELECT * FROM NewsClass ORDER BY ORDERID DESC
"
;
2![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
OleDbConnection conn
=
new
OleDbConnection();
4![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
conn.ConnectionString
=
ConnectionString;
6
conn.Open();
7![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
OleDbCommand cmd
=
new
OleDbCommand(Sql,Conn);
9
OleDbDataReader dr
=
cmd.ExecuteReader();
10![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
//
将数据添加到 DropDownList
12
while
(dr.Read())
13![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
14
ddl.Items.Add(new ListItem(dr["ClassName"].ToString(),dr["ClassId"].ToString()));
15
}
16
dr.Close();
17![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
cmd.Dispose();
19
conn.Close;
20
conn.Dispose();
21
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
14
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![ExpandedBlockEnd.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
16
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
方法二:
1
string
sql
=
"
SELECT * FROM NewsClass ORDER BY ORDERID DESC
"
;
2![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
OleDbConnection conn
=
new
OleDbConnection();
4
conn.ConnectionString
=
ConnectionString;
5
conn.Open();
6![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
DataSet ds
=
new
DataSet();
8
OleDbDataAdapter da
=
new
OleDbDataAdapter(sql,conn);
9
da.Fill(ds,
"
ClassTable
"
);
10![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
//
将数据添加到 DropDownList
12
ddl.DataSource
=
ds;
13
ddl.DataTextField
=
"
ClassName
"
;
14
ddl.DataValueField
=
"
ClassID
"
;
15
ddl.DataBind();
16![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
ds.Dispose();
18
conn.Close;
19
conn.Dispose();
20![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)