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 }
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 }
相关文章推荐
- ADO.net中临时表DataTable的简单应用
- 小小的总结一下java异常处理和List、ArrayList、Vector、Set、HashSet、TreeSet集合的简单应用
- DataTable的简单应用
- 学习笔记(一)C#基础和泛型List和DataTable和HashTable和Dictionary的简单用法--存值 取值
- OAF_开发系列17_实现OAF数组应用Vector / Hashmap / Hashtable / Arraylist(案例)
- Hashtable简单应用
- winform程序之录入删除显示人员应用了一点arraylist(简单)
- [C++]数据结构:散列表HashTable的实现与简单应用
- .Net中的Hashtable简单介绍和应用 (转Eric.liu's Tech Space)
- 分享一个基于java ArrayList的简单MQ队列,用在连接多个蓝牙设备一个一个连接的应用中
- winform程序之人员选择listbox控件应用了一点arraylist(简单)
- C#ArrayList简单应用
- DataTable的简单应用
- java学习-JAVA基本排序法示例,JAVA数据类型转换 ,ArrayList用法,Calendar 简单应用
- C#ArrayList简单应用
- ArrayList、Hashtable、DataTable、DataView、DataReader和DataSet,DataGrid等的区别和各自的优缺点
- DataSet,DataTable,DataView的关系及简单应用
- 集合简单总结 ArrayList、List、Hashtable、Dictionary
- 公司需求知识自学- Hashtable简单应用
- ArrayList、Hashtable、DataTable、DataView、DataReader和DataSet,DataGrid等的区别和各自的优缺点