会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
过江的博客
博客园
首页
新随笔
管理
订阅
合并两个DataTable
SqlConnection myConnection
=
new
SqlConnection(
"
server=localhost;uid=sa;pwd=;database=wjoa
"
);
string
sql1
=
"
select * from ResourseManage_T
"
;
SqlDataAdapter adapterA
=
new
SqlDataAdapter(sql1,myConnection);
DataSet ds
=
new
DataSet();
adapterA.Fill(ds,
"
a
"
);
string
sql2
=
"
select * from UserLogin_t
"
;
if
(myConnection.State
!=
ConnectionState.Closed)
myConnection.Close();
adapterA
=
new
SqlDataAdapter(sql2, myConnection);
adapterA.Fill(ds,
"
b
"
);
DataTable dtParent
=
ds.Tables[
"
a
"
];
DataTable dtChild
=
ds.Tables[
"
b
"
];
DataRow dr;
for
(
int
i
=
0
;i
<
dtChild.Rows.Count;i
++
)
{
dr
=
dtParent.NewRow();
for
(
int
j
=
0
;j
<
dtParent.Columns.Count;j
++
)
{
dr[j]
=
dtChild.Rows[i][j];
}
dtParent.Rows.Add(dr);
}
this
.DataGrid1.DataSource
=
ds.Tables[
"
a
"
].DefaultView;
this
.DataGrid1.DataBind();
posted on
2006-06-23 15:44
过江
阅读(
1116
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告