我想获取sit.instrcode、sit.pointid、it.instrtype 字段中的数据,最后封装到和一个类中,并每次添加到ArrayList中。
    public static ArrayList readPointId(string stationId ,string oracleConnStr)
    {
        ArrayList list = new ArrayList();
        string sql = "select sit.instrcode,sit.pointid,it.instrtype from qzdata.qz_dict_stationinstruments sit,QZDATA.QZ_DICT_INSTRUMENTS it where sit.instrcode like'312%' and sit.stationid='" + stationId + "' and it.instrcode=sit.instrcode";
        using (OracleConnection conn = new OracleConnection(oracleConnStr))
        {
            conn.Open();
            using (OracleCommand cmd = new OracleCommand(sql, conn))
            {
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while(dr.Read())
                    {
                        Point p = new Point();
                        p.InstrCode = dr.GetString(0);
                        p.PointId = dr.GetString(1);
                        p.InstrType = dr.GetString(2);
                        list.Add(p);
                    }
                }
            }
        }
        return list;
    }
但Point封装后的值和数据库中的值有很大的出入:数据库中查询如下:
INSTRCODE  POINTID  INSTRTYPE
3121504    1        FHD-2程序封装后如下:p.InstrCode    3121504
p.PointId      FHD-2
p.InstrType    NULL我怀疑我的查询有问题,我是新手不知道怎么改,求教了~!

解决方案 »

  1.   

    p.PointId = dr.GetInt(1);
      

  2.   

                           p.InstrCode = dr.GetString(0);
                            p.PointId = dr.GetInt32(1);
                            p.InstrType = dr.GetString(2);
      

  3.   

    谢谢 我的PointId字段是varchar的,不过已经解决了!
    是我马虎了 我写错了 把PointID 值给instrType了 真晕死我了下面是错误的代码:public class Point
    {
        private string instrCode;
        private string pointId;
        private string instrType; public Point()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }    public string InstrCode
        {
            get { return instrCode; }
            set { instrCode = value; }
        }    public string PointId
        {
            get { return pointId; }
            set { pointId = value; }
        }    public string InstrType
        {
            get { return instrType; }
            set { pointId = value; }
        }
        
    }