读书人

数据库循环查询的多条数据怎么填充进同

发布时间: 2012-12-17 09:31:40 作者: rapoo

数据库循环查询的多条数据如何填充进同一个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 ...)



可是我预计不了这个i< dt.Rows.Count的值会有多大,这个是动态变化的啊
[其他解释]
sqldatareader
[其他解释]

引用:
sqldatareader


大虾可否详细点呢?
[其他解释]
引用:
引用:
引用:你可以把这些查询和并在一起,最简单。

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

可是我预计不了这个i< dt.Rows.……


我觉得假如i=10的话,那我就要写(select ... from ... where ...) union (select ... from ... where ...) union (select ... from ... where ...)
十个查询条件喇,况且现在i的值不确定呢
[其他解释]
引用:
看了下你的代码,好呆

你不能用子查询么?
select ... from ... where process_name in (你之前的那个dt的查询) ... and status = 'Active'

我把代码该成了
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 in ('" + dt.Rows[i]["加工工艺"].ToString()
+ "') and customer_name in ('" + dt.Rows[i]["客户代码"].ToString()
+ "') and part_spec1 in ('" + dt.Rows[i]["客户型号"].ToString()
+ "') and status = 'Active'";
}
da = SelectOracleDT.getProduct(lineproduct);
运行发现还是只查出来是最后一条数据呀,前面的数据都被覆盖掉了
[其他解释]
引用:
晕,不是这么用的。

你google下sql in 子查询。

其实dt是另一个datatable来的,现在要做的是根据这个datatable的值到数据库查询条件符合的并把查询出来的集合填充到同一datatable里的
[其他解释]

有哪位大神帮帮忙吗?我是初学者,还不怎么了解呢

读书人网 >.NET Framework

热点推荐