首先我真的很菜啊!在网上找了N个arraylist的用法,居然没找到我想要的资料!我的具体想法是这样
string SqlDh = "select dh from division where kh='" + Kh + "'";为查询语句,想将此语句产生的一列值赋值给arraylist,并且能够将它们从arraylist取出,具体应该怎么做呢?谢谢了!

解决方案 »

  1.   

        public ArrayList select_id(string str_IDS) 
            { 
                SqlParameter patrameter = new SqlParameter("@kh", SqlDbType.VarChar,50); 
                patrameter.Value = str_IDS; 
    ArrayList list=new ArrayList();
                using (SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectString"])) 
                { 
                    try 
                    { 
                        conn.Open(); 
                        string str_sql = @"select dh from division where kh=@kh"; 
                        SqlCommand cmd = new SqlCommand(); 
                        cmd.Connection = conn; 
                        cmd.CommandType = CommandType.Text; 
                        cmd.CommandText = str_sql; 
                        cmd.Parameters.Add(patrameter); 
                       SqlDataReader read= cmd.ExecuteDataReader(); while(read.Read())
    {
      list.Add(read["dh"]);
    }
                        conn.Close(); 
                    } 
                    catch (Exception ex) 
                    { 
                    } 
                } 
    return list;
            }
    实在懒的写了。
      

  2.   

    赋值我看到了,是这个list.Add(read["dh"]); 对吧,可是如何取值呢?还求楼上再赐教!
      

  3.   

    string Dh = ALDh[i].ToString();对吗?
      

  4.   

    对的,你直接写个for循环
    for(int i=0;i<ALDh.count;i++)
    {
       string Dh = ALDh[i].ToString();
    }
      

  5.   

    谢谢ericzhangbo1982111和zhensoft163