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!

解决方案 »

  1.   

    一个DataGrid只能绑定一个DataTable~
      

  2.   

    DataGrid1.DataSource=DisDs.Tables[i];
    DataGrid1.DataBind();
      

  3.   

    DataGrid1.DataSource=DisDs.Tables["TableName"];
    DataGrid1.DataBind();ok?
      

  4.   

    我将几个DataTables放到一个DataSet中, 我先在DataGrid中显示这个dataset.但是只能显示第一个DataTable. 我怎样才能DataGrid中显示所有的DataTable?不同的DataTable列值都不同, 而且某些DataTable之间没有任何关系.有好的想法吗? 非常感谢!
      

  5.   

    一个DataAdapter一般只调用一张表,从DB从读取的数据随着一条SQL-select而读到一张表里头去.所以这就是我用一个DataAdapter只能得到几张一摸一样内容的表的原因,因为他们的数据本身就是在一起的,不管在DataSet中创建多少表,只要这个来源是DataAdapter,他们的内容就是一样的
      

  6.   

    //......
    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");
    //........
      

  7.   

    my DataSet have several DataTables, so I hope that one DataGrid is enough to show this DataSet which contains tens of DataTables.One common thing, most of the DataTables will show two columns, a few DataTable will show one column.
      

  8.   

    你可以把多个DataTable合并为一个再显示
      

  9.   

    But different DataTable have different columns. Is it possible to combine the data in DataTable, don't consider the columns name?Since some DataTables do not have any relations.
      

  10.   

    没有关系的话 为什么不能合并呢?
    列名无所谓的,相同的话改个名,再把DataColumn.Caption设为原来的列名
      

  11.   

    you can do like this:
    grid1.DataSource = dataset1;
      

  12.   

    you can add relations between tables.ref:
    http://www.syncfusion.com/faq/windowsforms/search/780.aspx
      

  13.   

    to Since some DataTables do not have any relations.It is unreasonable to show different tables without relations in one datagrid.
      

  14.   

    It will make your client confused.
      

  15.   

    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!
      

  16.   

    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.
      

  17.   

    DataGrid1.DataSource=DisDs.Tables["TableName"];
    DataGrid1.DataBind();就行了
      

  18.   

    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.
      

  19.   

    Read from your several datatable manually.
      

  20.   

    cycle to read datatables to display.Or use DropDownList to choose which datatable to display.
      

  21.   

    如果您只是为了显示结果,可以加入一个下拉框,邦定所有的表名,在选择项事件中使datagrid重新绑定。
      

  22.   

    你在想显示某个table时再重新绑定一下
      

  23.   

    你不设置DataMember的属性值,然后直接将DataSource 绑定为 DataSet,各个表在DataGrid里就会以树结点的形势显示,点击哪个结点就显示哪个表的数据