日期:2014-05-20  浏览次数:20695 次

数据库循环查询的多条数据如何填充进同一个datatable
数据库循环查询的数据
String lineproduct = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lineproduct = "select name as 产品名,std_size as 产品规格,object_rrn as 产品RRN,version as 产品版本,description as 产品描述 from meswell.prd_part "
                 + "where process_name ='" + dt.Rows[i]["加工工艺"].ToString()
                 + "'and customer_name ='" + dt.Rows[i]["客户代码"].ToString()
                 + "'and part_spec1 ='" + dt.Rows[i]["客户型号"].ToString()
                 + "'and status = 'Active'";
                da = SelectOracleDT.getProduct(lineproduct);
            }

public static DataTable getProduct(String lineproduct)
        {
             DataTable dc = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(lineproduct, conn);
             da.Fill(dc);
             return dc;
        }

上面代码,我觉得是不能用Fill填充的,但是又不知道怎么来修改,请大虾们给点思路,谢谢




------最佳解决方案--------------------
引用:
引用:你可以把这些查询和并在一起,最简单。

(select ... from ... where ...) union (select ... from ... where ...) union (select ... from ... where ...)

可是我预计不了这个i< dt.Rows.Count的值会有多大,这个是动……


那有什么关系。
------其他解决方案--------------------
看了下你的代码,好呆

你不能用子查询么?
select ... from ... where process_name in (你之前的那个dt的查询) ... and status = 'Active'
------其他解决方案--------------------
晕,不是这么用的。

你google下sql in 子查询。
------其他解决方案--------------------
你可以把这些查询和并在一起,最简单。

(select ... from ... where ...) union (select ... from ... where ...) union (select ... from ... where ...)
------其他解决方案--------------------
引用:
你可以把这些查询和并在一起,最简单。

(select ... from ... where ...) union (select ... from ... where ...) union (select ... from ... where ...)