string str = "select top 3 Pname,count(PNum) as Num,sum(TotalPrice) as price from [order] group by PName order by price desc";
DataSet ds = SqlHelper.Queryall(str);
..
..
..
现在代码是这样的。我想把查出来的Num,和Price 分别放到两个数组里。例如
Num中为 1,2,3,4,5 和 Price中为 5.5,4.5,3.5,2.5,1.5 时
我想要将它分别放到两个数组里
int[] Num={1,2,3,4,5};
float Price={ 5.5,4.5,3.5,2.5,1.5};
请问应该怎么弄,请代码相告,谢谢!
int count = ds.Tables[0].Rows.Count;
int[] num = new int[count];
float[] price = new float[count];
int i = 0;
foreach(DataRow row in ds.Tables[0].Rows){
num[i] = (int)row["num"];
price[i]=(float)row["price"];
i++;
}
建立两个数组,遍历DataSet的DataTable相关列赋值。