How to bind muti-DataTable to one DataGrid(GridView)?

angel_lee 2006-07-28 11:23:24
I added several DataTables to one DataSet, and want to display this DataSet on DataGrid.

But it only display the first DataTable. How can I display all the DataTables on one DataGrid?

Different DataTable have different columns, and some of them do not have any relations.

Any advice or good idea? Thanks a lot!
...全文
224 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovebingye 2006-08-01
  • 打赏
  • 举报
回复
你不设置DataMember的属性值,然后直接将DataSource 绑定为 DataSet,各个表在DataGrid里就会以树结点的形势显示,点击哪个结点就显示哪个表的数据
wcmj 2006-07-31
  • 打赏
  • 举报
回复
你在想显示某个table时再重新绑定一下
yan63 2006-07-31
  • 打赏
  • 举报
回复
如果您只是为了显示结果,可以加入一个下拉框,邦定所有的表名,在选择项事件中使datagrid重新绑定。
mmens 2006-07-31
  • 打赏
  • 举报
回复
cycle to read datatables to display.Or use DropDownList to choose which datatable to display.
Yellow198267 2006-07-31
  • 打赏
  • 举报
回复
可以绑定多个
zeusvenus 2006-07-31
  • 打赏
  • 举报
回复
Read from your several datatable manually.
angel_lee 2006-07-31
  • 打赏
  • 举报
回复
The real result files located in File System. I only need to show the search result which is a file index in datagrid. But the search result comes from different tables.
marvelstack 2006-07-29
  • 打赏
  • 举报
回复
show in two datagrid,
smartstar2005 2006-07-29
  • 打赏
  • 举报
回复
顶一下
angel_lee 2006-07-29
  • 打赏
  • 举报
回复
It won't make any client confuse, since it's search results that will show in one datagrid, they needn't have any relations.

Do you have any good idea?

Thanks!
懒是一种态度 2006-07-29
  • 打赏
  • 举报
回复
DataGrid1.DataSource=DisDs.Tables["TableName"];
DataGrid1.DataBind();

就行了
Knight94 2006-07-29
  • 打赏
  • 举报
回复
It will make your client confused.
Knight94 2006-07-29
  • 打赏
  • 举报
回复
to Since some DataTables do not have any relations.

It is unreasonable to show different tables without relations in one datagrid.
Knight94 2006-07-29
  • 打赏
  • 举报
回复
you can add relations between tables.

ref:
http://www.syncfusion.com/faq/windowsforms/search/780.aspx
Knight94 2006-07-29
  • 打赏
  • 举报
回复
to It won't make any client confuse, since it's search results that will show in one datagrid, they needn't have any relations.


Since these tables are search results, you should get breaf info from results to create an index table which will be shown in datagrid.
aSalt 2006-07-29
  • 打赏
  • 举报
回复
only one
liangge 2006-07-29
  • 打赏
  • 举报
回复
you can do like this:
grid1.DataSource = dataset1;
ericksky 2006-07-29
  • 打赏
  • 举报
回复
只能绑定一个吧?
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
//......
SqlDataCommand str1=new SqlDataCommand("select * from Categories",connection);
SqlDataCommand str2=new SqlDataCommand("select * from Employees",connection);
SqlDataCommand str3=new SqlDataCommand("select *from Customers",connection);
SqlDataAdapeter da=new SqlDataAdapter();
DataSet ds=new DataSet();
connection.open();
da.SelectCommand=str1;
da.Fill(ds,"table1");
da.SelectCommand=str2;
da.Fill(ds,"table2");
da.SelectCommand=str3;
da.Fill(ds,"table3");
//........
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
一个DataAdapter一般只调用一张表,从DB从读取的数据随着一条SQL-select而读到一张表里头去.所以这就是我用一个DataAdapter只能得到几张一摸一样内容的表的原因,因为他们的数据本身就是在一起的,不管在DataSet中创建多少表,只要这个来源是DataAdapter,他们的内容就是一样的
加载更多回复(12)

110,533

社区成员

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

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

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