有两个表通过主键关联,我知道主键是什么,但不知道列数(列数是不确定的,通过另一张表给出他们的列,以及要显示的列),我要从中选出需要的列组合成新表显示出来,在修改后需要更新.     system 表---记录所有的列,以及要显示的列,字段如下:
tablename   fieldname   visible
 table1       a           0
 table1       b           1
 table1       c           1
 table2       a           0
 table2       b           0
 table2       c           1
---已知table1.a于table2.a关联   
---select table1.b,table1.c,table2.c from table1,table2 where table1.a=table2.a
我的思路是各自选出所有的字段,放入DataSet中,然后组合并显示(隐藏掉不显示的列),但不知该怎样组合,不知改怎样更新。
先谢过了!

解决方案 »

  1.   

    设你有一个SqlCommand 或 OleDbCommand or sth else
    叫 cmd;
    string sql = "select visible from system where tablename = 'table1' and fieldname='a'";int i = int.Parse(cmd.ExecuteScalar(sql).ToString());if (i == 0)
    {
    //楼主应该是用dataGrid显示吧
    //hide the columndataGrid.TableStyles[0].GridColumnStyles["字段名"].Width = 0;
    }
      

  2.   

    各自选出所有的字段,放入DataSet中,然后组合并显示 。   这个功能可以通过拼写sql语句来实现,select A.a,A.b,B.c,B.d  from t1 A inner join  t2 B on t1.a = t2.a 用程序组合语句。
      

  3.   

    关键字:DataTable/DataRow/DataColumn/Foreach ,查阅msdn
      

  4.   

    读取表的结构,进行分析
    http://blog.csdn.net/zhzuo/archive/2004/07/03/33273.aspx