现在有个项目,有两张表一张是物料表,一张是出入库明细表。现在想得到三个月未出入库的物料,三个月有入库没出库的物料,三个月有出库没入库的物料。
我现在用asp.net做的是:将物料表,出入库明细表数据读出来存到datetable,分别为table1,table2。通过程序table1和table2进行比对。 private readonly DAL.MaterialsStorage mast = new DAL.MaterialsStorage();
        public DataTable GetMaterialsList()
        {
            DataTable table1 = mast.GetFullMaterialsStorage().Tables[0];
            DataTable table2 = mast.GetOutOfMaterialsStorage().Tables[0];
            DataTable NewTable = new DataTable();
            DataColumn ITEM_CD = new DataColumn("ITEM_CD", typeof(string));
            NewTable.Columns.Add(ITEM_CD);
            ArrayList ay = new ArrayList();
            if (table1 != null && table1.Rows.Count != 0 && table2 != null && table2.Rows.Count != 0)
            {
                for (int i = 0; i < table1.Rows.Count; i++)
                {
                    for (int y = 0; y < table2.Rows.Count; y++)
                    {
                        if (table1.Rows[i]["ITEM_CD"].ToString() != table2.Rows[y]["ITEM_CD"].ToString() && !ay.Contains(table1.Rows[i][0]))
                        {
                            DataRow row = NewTable.NewRow();
                            row = table1.Rows[i];
                            NewTable.Rows.Add(row[0]);
                            ay.Add(row[0]);
                        }
                    }
                }
            }
            return NewTable;
        }
但是两张表的数据量比较大,运行时间太长了,我的机器配置不高,运行了老长时间都没出来结果。请大侠们提供一些其它思路或者是其它方法

解决方案 »

  1.   

    用存储过程 做.简单.高效
    直接用gridview绑定就可以了!
      

  2.   

    查三个月没出库的表
    select * from 物料表 where 物料表id not in(select * 出入表 where 出入状态=出库) and 时间在3个月内有入库没出库的表
    select * 出入表 where 物料id not in(select * 出入表 where 出入状态=入库)
    3个月有出库没入库
    select * 出入表 where 物料id not in(select * 出入表 where 出入状态=出库)
    感觉这样可以解决楼主的问题,楼主试下看可以不
      

  3.   

    做三次查询
      table1:查找未出入库的物料
      table2:查找入库未出库的物料
      table3:查找出库未入库的物料
       这样分开查询所得的数据应该会少很多(改sql语句).
      你这样做两次查询所得的数据会比较多,而且循环大量的数据也会耗时间的