ado.net 中想更新dataset中某一张表中的所有记录的某一列值怎么做呢?

xuhaoumsl 2008-05-05 07:01:52
dataset中有若干张表 customer, order,plan
customer table 有一个row

想把plan table 中所有的纪录的CustomerID这一列 更新成customer table 中那个row得CustomerID 如何做呢 谢谢
...全文
93 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shyboy8 2008-05-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 liubin911 的回复:]
你是想更新dataset还是数据库
不知道我理解的对不对,你想吧plan表所有列的CustomerID改成customer表中那一行的CustomerID
用for循环遍历

C# code

for (int i=0;i<=dataset1.Tables["plan"].Rows.Count;i++)
{
ds.Tables["plan"].Rows[i]["CustomerID"]=ds.Tables["customer"].Rows[0]["CustomerID"].ToString();
}




更新数据库也差不多
[/Quote]
引用了
xieyongbao 2008-05-05
  • 打赏
  • 举报
回复
是< 不是<= 否则会越界
for (int i=0;i<ds.Tables["plan"].Rows.Count;i++)
{
ds.Tables["plan"].Rows[i]["CustomerID"]=ds.Tables["customer"].Rows[0]["CustomerID"].ToString();
}
liubin911 2008-05-05
  • 打赏
  • 举报
回复
你是想更新dataset还是数据库
不知道我理解的对不对,你想吧plan表所有列的CustomerID改成customer表中那一行的CustomerID
用for循环遍历


for (int i=0;i<=dataset1.Tables["plan"].Rows.Count;i++)
{
ds.Tables["plan"].Rows[i]["CustomerID"]=ds.Tables["customer"].Rows[0]["CustomerID"].ToString();
}


更新数据库也差不多
yagebu1983 2008-05-05
  • 打赏
  • 举报
回复
用视图啊!
journeydj 2008-05-05
  • 打赏
  • 举报
回复
自己写sql
songyangaaron 2008-05-05
  • 打赏
  • 举报
回复
类似这样的情况应该用SQL语句操作数据库吧 update plan set CustomerID = ...

如果一定要在DataTable中操作的话就遍历一下呗 foreach (DataRow r in plan.Rows) r["CustomerID"] = ...;
xuhaoumsl 2008-05-05
  • 打赏
  • 举报
回复
谢谢 4楼 7楼 1楼的朋友 还有其他的朋友 小弟对ado.net这里不是很熟悉 受用了.

110,539

社区成员

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

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

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