C# SQL语句查询出来的字段放入数组中

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:19:13
string strSql = "Select 颜色名称 From 颜色表";

string[] str名称数组 = new string[]{};

我想把Sql语句中查询出来的"颜色名称"字段里面的数据,
放入数组"str名称数组"里面?
怎么放?

把查询出来的数据集放到DataTable中,然后使用for循环,大致思想如下:
for(int i=0;i<dt.Rows.Count;i++)
{
str[i]=dt.Rows[i]["颜色名称"].toString();
}

假设SELECT后的结果集为rd

int i=0;
while(rd.read())
{
str[i]=rd["颜色名字"].toString();
i++;
}