数组问题 循环赋值 取值

一个吃瓜群众 2012-08-23 10:26:15

int i = 1;
foreach (DataRow dr in dt.Rows)
{
gkxx = new Proj_cfxfgkxx();
gkxx.lxdh = dr["联系电话"].ToString();
}

我想将循环出来的gkxx.lxdh放到一个List中

之后有个判断,循环取值判断lxdh是否存在于另一个表中
"select * from ---- where lxdh="+gkss.lxdh

不知道怎么写了,迷糊。
网上找了大半天,求助!!
...全文
133 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
List<string> temp_list = dt.AsEnumerable().Select(a => a.Field<string>("lxdh")).ToList();

判断
bool flag=dt.Select("lxdh='" + gkss.lxdh+"'").Count()>0;


bdmh 2012-08-23
  • 打赏
  • 举报
回复
foreach中判断
if (finditem(gkxx.lxdh))

finditem自己写就行了,最简单的就是遍历查,或者用LINQ
E次奥 2012-08-23
  • 打赏
  • 举报
回复
我还是不知道LZ要干什么!

放到LIST很简单,实例化一个LIst集合,在foreach循环里Add就OK!
后边要干什么就不知道了,请楼主说明!
shizhu820228 2012-08-23
  • 打赏
  • 举报
回复
gkxx.lxdh 是个List<string>吧?

foreach (DataRow dr in dt.Rows)
{
gkxx = new Proj_cfxfgkxx();
//填加到List里
gkxx.lxdh.Add(dr["联系电话"].ToString());
}
//转成string加","
string s = string.Join("','",gkxx.lxdh.ToArray());

//写你的SQL
select * from ---- where lxdh in ('" + s + "')"
判断就行了。



110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧