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);......現(xiàn)在代碼是這樣的。我想把查出來的Num,和Price 分別放到兩個數(shù)組里。例如 Num中為 1,2,3,4,5 和 Price中為 5.5,4.5,3.5,2.5,1.5 時 我想要將它分別放到兩個數(shù)組里 int[] Num={1,2,3,4,5}; float Price={ 5.5,4.5,3.5,2.5,1.5}; 請問應該怎么弄,請代碼相告,謝謝!
2 回答

蝴蝶刀刀
TA貢獻1801條經(jīng)驗 獲得超8個贊
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++;
}
- 2 回答
- 0 關(guān)注
- 510 瀏覽
添加回答
舉報
0/150
提交
取消