现在有个项目,有两张表一张是物料表,一张是出入库明细表。现在想得到三个月未出入库的物料,三个月有入库没出库的物料,三个月有出库没入库的物料。
我现在用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;
}
但是两张表的数据量比较大,运行时间太长了,我的机器配置不高,运行了老长时间都没出来结果。请大侠们提供一些其它思路或者是其它方法
我现在用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;
}
但是两张表的数据量比较大,运行时间太长了,我的机器配置不高,运行了老长时间都没出来结果。请大侠们提供一些其它思路或者是其它方法
解决方案 »
- 急急急!用MVC框架 求一个从数据库导出数据到EXCEL的方法 不要csv格式的
- 求解:asp.net画图不能正常显示
- 求"HTTP 405 - 资源被禁止"的解求办法
- Page_Load 里动态生成RadioButtonList,如果在另一方法中调用(本人调用提示不存在)
- 怎么在局域网里面搭建ASP.net程序,让局域网的电脑都能访问。100分
- 菜鸟求助
- 关于DataGrid中删除列的提示问题
- 求在datagrid分页中包含一个dropdownlist控件分页的代码的例子.
- 如何判断一个整型变量是否为空? c#
- 求助!
- Asp.net程序Response.Redirect() 在IIS中调试很慢
- fckeditor无法上传图片怎么办
直接用gridview绑定就可以了!
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 出入状态=出库)
感觉这样可以解决楼主的问题,楼主试下看可以不
table1:查找未出入库的物料
table2:查找入库未出库的物料
table3:查找出库未入库的物料
这样分开查询所得的数据应该会少很多(改sql语句).
你这样做两次查询所得的数据会比较多,而且循环大量的数据也会耗时间的