zoukankan      html  css  js  c++  java
  • Hashtable与DataTable,ArrayList的简单应用(转自cnblogs)


     1 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        }
  • 相关阅读:
    关于VS2010“ADO.NET Entity Data Model模板丢失或者添加失败问题
    Swagger的配置方法
    asp.net core的cookie认证
    abap程序开发
    闲置7成新二手图书处理(待更新)
    Winform 调用C++ OCX 传入参数和传出参数问题
    Html上传图片问题
    服务器端输出到客户端
    IE8下居然页面突然看不了
    解决Arial字体“高低肩问题”
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/857672.html
Copyright © 2011-2022 走看看