private static DataTable GetAllBus()
    {
        DataTable dt = new DataTable("dtBus");
        DataColumn col;
        DataRow row;        //ID
        col = new DataColumn("ID", System.Type.GetType("System.Int32"));
        dt.Columns.Add(col);        //名称
        col = new DataColumn("Name", System.Type.GetType("System.String"));
        dt.Columns.Add(col);        //父ID
        col = new DataColumn("PID", System.Type.GetType("System.Int32"));
        dt.Columns.Add(col);        //层级
        col = new DataColumn("Level", System.Type.GetType("System.Int32"));
        dt.Columns.Add(col);        ////////////////////车次///////////////////
        string[,] busList = Goodjob.Common.Dictionary.ArrayBus.pyBusTypeDict;        int len = busList.Length / 2;
        for (int i = 0; i < len; i++)
        {
            row = dt.NewRow();
            row["ID"] = Convert.ToInt32(busList[i, 1]);
            row["Name"] = busList[i, 0];
            row["PID"] = -1;
            row["Level"] = 1;
            dt.Rows.Add(row);        }        //////////站点/////////////////////////
        len = dt.Rows.Count;
        for (int i = 0; i < len; i++)
        {
            int busID = (int)dt.Rows[i]["ID"];
            string[,] stationList = Goodjob.Common.Dictionary.ArrayBus.GetBus(busID );            int size = stationList.Length / 2;
            for (int j = 0; j < size; j++)
            {
                row = dt.NewRow();
                row["ID"] = Convert.ToInt32(stationList[j, 1]) * 1000;
                row["Name"] = stationList[j, 0];
                row["PID"] = busID;
                row["Level"] = 2;
                dt.Rows.Add(row);
            }
        }     
        return dt;
     
    }
int busID = (int)dt.Rows[i]["ID"];
获取不到值,是怎么回事啊?那位大侠帮帮忙,看看是什么原因

解决方案 »

  1.   

    看下dt.Rows.Count是否为0.
    不知道你的int busID = (int)dt.Rows[i]["ID"];从哪里调用的,是用的ASP.NET还是WinForm,dt是怎么传递的,这些都是推断的必要因素
      

  2.   

    是用的ASP.NET 我想把上面row["ID"] = Convert.ToInt32(busList[i, 1]);
    获得的值赋值给ring[,] string[,] stationList = Goodjob.Common.Dictionary.ArrayBus.GetBus(busID );不知这样写对吗?获取不了值
      

  3.   

    你这句里面有值吗?
    string[,] busList = Goodjob.Common.Dictionary.ArrayBus.pyBusTypeDict;打一个断点在那句看看,是不是上面就么有值?
      

  4.   


    string[,] busList = Goodjob.Common.Dictionary.ArrayBus.pyBusTypeDict;有值