是这样的执行到sql语句时通过查询分析器得到的记录是对的 把他们放到ArrayList 数组里最后一个记录却把前面的记录覆盖了 但是在页面上显示的个数是一样的 记录却是相同的(最后一个记录的)
代码如下
public ArrayList getLastYearThreePolluteRuleInfo(string factID,string year)
{
IDbCommand command = DataAccess.GetCommand();
ArrayList resultArrayList = new ArrayList();
command.CommandType = CommandType.Text ;
command.CommandText = "select 治理设施名称,污染类别名称,处理方法名称,设计处理能力,"+
"处理量,排放口名称,设施编码,污染类别,排放口编码 from CommonDeclare1_2_View where 企业编码 = '"+factID+"' and 年份= '"+year+"'"; IDataReader reader = DataAccess.ExecuteReader(command,null);
try
{
while(reader.Read())
{
CommonDeclare1_2Unit common1_2Unit = new CommonDeclare1_2Unit();
common1_2Unit = getCommonDeclare1_2Unit(reader);
resultArrayList.Add(common1_2Unit);
}
return resultArrayList;
}
catch(Exception exp)
{
string errorMsg = exp.Message ;
return null;
}
finally
{
if(reader != null)
{
reader.Close();
}
m_Command = null;
}
}
getCommonDeclare1_2Unit 方法如下:
public CommonDeclare1_2Unit getCommonDeclare1_2Unit(IDataReader reader)
{
unit = new CommonDeclare1_2Unit();
unit.RuleFacilName = reader.GetString(0);
unit.PolluteTypeName = reader.GetString(1);
unit.RuleMethod = reader.GetString(2);
unit.DesignRuleAble = reader.GetDecimal(3);
unit.RuleAmount = reader.GetDecimal(4);
unit.OutputNameAndID = reader.GetString(5);
unit.RuleID = reader.GetInt32(6);
unit.PolluteType = reader.GetString(7);
unit.OutputID = reader.GetInt32(8);
return unit;
}
#endregion
前台是一个DataList的帮定
谢谢 回答@!
代码如下
public ArrayList getLastYearThreePolluteRuleInfo(string factID,string year)
{
IDbCommand command = DataAccess.GetCommand();
ArrayList resultArrayList = new ArrayList();
command.CommandType = CommandType.Text ;
command.CommandText = "select 治理设施名称,污染类别名称,处理方法名称,设计处理能力,"+
"处理量,排放口名称,设施编码,污染类别,排放口编码 from CommonDeclare1_2_View where 企业编码 = '"+factID+"' and 年份= '"+year+"'"; IDataReader reader = DataAccess.ExecuteReader(command,null);
try
{
while(reader.Read())
{
CommonDeclare1_2Unit common1_2Unit = new CommonDeclare1_2Unit();
common1_2Unit = getCommonDeclare1_2Unit(reader);
resultArrayList.Add(common1_2Unit);
}
return resultArrayList;
}
catch(Exception exp)
{
string errorMsg = exp.Message ;
return null;
}
finally
{
if(reader != null)
{
reader.Close();
}
m_Command = null;
}
}
getCommonDeclare1_2Unit 方法如下:
public CommonDeclare1_2Unit getCommonDeclare1_2Unit(IDataReader reader)
{
unit = new CommonDeclare1_2Unit();
unit.RuleFacilName = reader.GetString(0);
unit.PolluteTypeName = reader.GetString(1);
unit.RuleMethod = reader.GetString(2);
unit.DesignRuleAble = reader.GetDecimal(3);
unit.RuleAmount = reader.GetDecimal(4);
unit.OutputNameAndID = reader.GetString(5);
unit.RuleID = reader.GetInt32(6);
unit.PolluteType = reader.GetString(7);
unit.OutputID = reader.GetInt32(8);
return unit;
}
#endregion
前台是一个DataList的帮定
谢谢 回答@!
resultArrayList.Add(common1_2Unit);或者:CommonDeclare1_2Unit common1_2Unit = new CommonDeclare1_2Unit();
common1_2Unit = getCommonDeclare1_2Unit(reader,common1_2Unit);
resultArrayList.Add(common1_2Unit);public CommonDeclare1_2Unit getCommonDeclare1_2Unit(IDataReader reader,CommonDeclare1_2Unit unit)
{
unit.RuleFacilName = reader.GetString(0);
unit.PolluteTypeName = reader.GetString(1);
unit.RuleMethod = reader.GetString(2);
unit.DesignRuleAble = reader.GetDecimal(3);
unit.RuleAmount = reader.GetDecimal(4);
unit.OutputNameAndID = reader.GetString(5);
unit.RuleID = reader.GetInt32(6);
unit.PolluteType = reader.GetString(7);
unit.OutputID = reader.GetInt32(8);
return unit;
}