调用过程 通过SqlDataReader获取多个值能返回 数字型数组吗? 在线...
RT:
private Decimal[] GetGradeAQty(string ProductNo,string ColorNo)
{
DataBase dbGrade = new DataBase();
string strSQL = null;
Decimal[] QtyValue;
int i = 0;
dbGrade.Open();
strSQL = "....... ";
SqlCommand objcmd = new SqlCommand(strSQL, dbGrade.cn);
SqlDataReader objReader = objcmd.ExecuteReader(CommandBehavior.CloseConnection);
while (objReader.Read())
{
QtyValue[i] = Convert.ToDecimal(objReader[0]);
i++;
}
dbGrade.Close();
return QtyValue[];
}
这样有误 (最好直接返回数字型的 用于计算)
------解决方案--------------------private void button1_Click(object sender, EventArgs e)
{
int[] ret = test();
}
private int [] test()
{
int[] QtyValue = new int[3];
QtyValue[0] = 1;
QtyValue[1] = 2;
QtyValue[2] = 3;
return QtyValue;
}
------解决方案--------------------try..
ArrayList list=new ArrayList();
while(datareader.Read());
{
list.Add(Convert.ToDecimal(datareader[0]);
}
return (decimal[])list.ToArray(typeof(decimal));