PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);

解决方案 »

  1.   

    PosGroup 是什么,出现了什么问题?
      

  2.   


     public  struct TPosGroup
        {
          
            public TLane Lane;    }    public struct TLane
        {
            public TRow[] Row;
        }    public struct TRow
        {
            public TCol[] Col;
        }    public struct TCol
        {
            public TLayer[] Layer;
        }    public struct TLayer
        {
            public TPos Pos;
        }    public struct TPos
        {
            public long PID;
            public int PosState;
            public int TypeOfState;
            public int TypeOfCusID;
            public int Zone_ID;
            public bool HasSetValue;    }
      

  3.   

    把 struct 都换成 class ,使用时都 new 实例化
      

  4.   

    数组长度设定一个合适的值
    public class TPosGroup
    {
        public TLane Lane = new TLane();
    }public class TLane
    {
        public TRow[] Row = new TRow[100];
    }public class TRow
    {
        public TCol[] Col = new TCol[100];
    }public class TCol
    {
        public TLayer[] Layer = new TLayer[100];
    }public class TLayer
    {
        public TPos Pos = new TPos();
    }public class TPos
    {
        public long PID;
        public int PosState;
        public int TypeOfState;
        public int TypeOfCusID;
        public int Zone_ID;
        public bool HasSetValue;
    }
      

  5.   


    if(ds1.Tables[0].Rows.Count>0)
                    {
                        for (int i = 0; i < ds1.Tables[0].Rows.Count;i++ )
                        {                        PosGroup.LastUpdateTime = Convert.ToInt32(ds1.Tables[0].Rows[i]["UPD"]);
                            IRow = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Line"]) - 1;
                            ICol = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Col"]) - 1;
                            ILayer = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Layer"]) - 1;                        //PosGroup.Lane = new publicpra.TLane();
                            //PosGroup.Lane.Row = new publicpra.TRow[2];
                            //PosGroup.Lane.Row[IRow].Col = new publicpra.TCol[14];
                            //PosGroup.Lane.Row[IRow].Col[ICol].Layer = new publicpra.TLayer[11];
                            //PosGroup.Lane.Row[IRow].Col[ICol].Layer[ILayer].Pos = new publicpra.TPos();
                                                   for(int m=0;m<=IRow;m++)
                            {
                                for (int n = 0; n <= ICol; ICol++)
                                {
                                    for (int h = 0; h <= ILayer;h++ )
                                    {
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);                                    PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);                                    PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
                                    }                            }                        }
                            
                        }
      

  6.   

    在PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
    提示:未将对象引用设置到对象的实例
      

  7.   

    PosGroup 声明的地方加上
    TPosGroup PosGroup = new TPosGroup();
      

  8.   

    把 for(int m=0;m<=IRow;m++) 循环整个换成下面的代码,看哪行出的错
    var lane = PosGroup.Lane;
    var row = lane.Row;for (int m = 0; m <= IRow; m++)
    {
        PosGroup.Lane.Row[m] = new TRow();
        for (int n = 0; n <= ICol; ICol++)
        {
            PosGroup.Lane.Row[m].Col[n] = new TCol();
            for (int h = 0; h <= ILayer; h++)
            {
                PosGroup.Lane.Row[m].Col[n].Layer[h] = new TLayer();
                PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
                PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);
                PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);
                PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
            }
        }
    }
      

  9.   


     if(ds1.Tables[0].Rows.Count>0)
                    {
                        for (int i = 0; i < ds1.Tables[0].Rows.Count;i++ )
                        {                        PosGroup.LastUpdateTime = Convert.ToInt32(ds1.Tables[0].Rows[i]["UPD"]);
                            IRow = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Line"]) - 1;
                            ICol = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Col"]) - 1;
                            ILayer = Convert.ToInt32(ds1.Tables[0].Rows[i]["NO_Layer"]) - 1;                        var lane = PosGroup.Lane;
                            var row = lane.Row;                        for (int m = 0; m <= IRow; m++)
                            {
                                PosGroup.Lane.Row[m] = new WMS_test.publicpra.TRow();
                                for (int n = 0; n <= ICol; ICol++)
                                {
                                    PosGroup.Lane.Row[m].Col[n] = new WMS_test.publicpra.TCol();
                                    for (int h = 0; h <= ILayer; h++)
                                    {
                                        PosGroup.Lane.Row[m].Col[n].Layer[h] = new WMS_test.publicpra.TLayer();
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PosState = Convert.ToInt32(ds1.Tables[0].Rows[i]["Pos_State"]);
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.Zone_ID = Convert.ToInt32(ds1.Tables[0].Rows[i]["Zone_ID"]);
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.PID = Convert.ToInt32(ds1.Tables[0].Rows[i]["PID"]);
                                        PosGroup.Lane.Row[m].Col[n].Layer[h].Pos.HasSetValue = true;
                                    }
                                }
                            }
      

  10.   

    for (int n = 0; n <= ICol; ICol++)
    改成
    for (int n = 0; n <= ICol; n++)
      

  11.   

    这就不用了,有问题在 CSDN 上提出,大家都会热心回答的