java+dataset+foreach_如何在我的代码中使用DataTable中的foreach DataRow获得高性能?

我从Oracle DB获得了一个数据表( ora_dt ),现在我需要在 ora_dt 中添加一个列( colu_sql ),但是我必须从某些Sqlserver数据库中获取 colu_sql 的值 .

这是我的代码:

public void ProcessDataTable(DataSet _ds)

{

_ds.Tables[0].Columns.Add(new DataColumn("Descpition", typeof(string)));

int countryId = -1;

string des_ID = string.Empty;

string geo = string.Empty;

foreach (DataRow row in _ds.Tables[0].Rows)

{

if (row["des_ID"] != DBNull.Value)

des_ID = row["des_ID"].ToString();

if (!string.IsNullOrEmpty(des_ID))

{

if (countryId == 12 || countryId == 13)

geo = "NA";

else if ((countryId == 10 || countryId == 11))

geo = "LA";

else

geo = "EMEA";

row["Descpition"] = GetDes(geo, des_ID);

}

else { row["ExemptionDes"] = string.Empty; }

}

}

对于每个DataRow,为了获得行["Descpition"]值,我必须检查它的 geo 和 des_id ,并从另一个SqlserverDB中选择它们 .

如果DataTable中的行计数非常大,那么当我使用DataTable时,我必须多次访问sqlserver db,这会使性能变差,

实际上我无法在Oracle.how中添加新的列描述在我的代码中使用DataTable中的foreach DataRow时可以获得高性能吗?

``

private string GetDes(string geo, string des_ID)

{

string description = string.Empty;

string query = "select description from geo_exemption where des_ID= " + des_ID;

Database DbSQL = DbSQLFactory.CreateDatabase(geo);

using (DataReader dr = DbSQL.ExecuteReader(sqlCmd))

{

while (dr.Read())

{

if (dr["description"] != null)

description = dr["description"].ToString();

}

dr.Close();

}

return description;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值