我在表中有5个名字,我需要把它们放在一个arraylist中....
有什么建议???
int rowsinmachgrp = getnumofrows();//gets no of rows in table
SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString = ConfigurationManager.ConnectionStrings["SumooHAgentDBConnectionString"].ConnectionString;
SqlCommand dataCommand =
new SqlCommand("select MachineGroupName from MachineGroups", dataConnection);
{ArrayList names = new ArrayList();
dataConnection.Open();
ArrayList names = dataCommand.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)
谢谢
这是你的:
List<string> names = new List<string>();
using(SqlConnection db = new SqlConnection(ConfigurationManager...))
{
db.Open();
SqlCommand cmd = new SqlCommand("Select ....", db);
using(SqlDataReader rd = cmd.ExecuteReader())
{
while(rd.Read())
{
names.Add(rd.GetString(0));
}
}
}
Run Code Online (Sandbox Code Playgroud)
没测试过!
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |