您的位置:首页 > 其它

Hashtable与DataTable,ArrayList的简单应用(转自cnblogs)

2007-08-16 10:10 423 查看
public void InitData()
2 {
3 string sql = @"select * from orders";
4
5 SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=sa;database=NorthWind");
6 SqlDataAdapter sda = new SqlDataAdapter(sql, con);
7 DataTable dt = new DataTable();
8 sda.Fill(dt);
9
10 Hashtable htt = new Hashtable(5);
11
12 foreach (DataRow dr in dt.Rows)
13 {
14 htt.Add(dr["orderID"], dr["CustomerID"]);
15
16 }
ArrayList al = new ArrayList(htt.Values);
al.Sort();
for (int i = 0; i < al.Count; i++)
{
//if (al[i].ToString() =="VINET")
//{
// Response.Write(al[i].ToString());
//}
Response.Write(al[i].ToString());
}
19 foreach (DictionaryEntry de in htt)
20 {
21 if (de.Value.ToString == "ALFKI")
22 {
23 Response.Write(de.Key + "Next .");
24 }
25 }
26 GridView1.DataSource = dt;
27 GridView1.DataBind();
28
29 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: