首先我真的很菜啊!在网上找了N个arraylist的用法,居然没找到我想要的资料!我的具体想法是这样
string SqlDh = "select dh from division where kh='" + Kh + "'";为查询语句,想将此语句产生的一列值赋值给arraylist,并且能够将它们从arraylist取出,具体应该怎么做呢?谢谢了!
string SqlDh = "select dh from division where kh='" + Kh + "'";为查询语句,想将此语句产生的一列值赋值给arraylist,并且能够将它们从arraylist取出,具体应该怎么做呢?谢谢了!
{
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;
}
实在懒的写了。
for(int i=0;i<ALDh.count;i++)
{
string Dh = ALDh[i].ToString();
}