首先sql语句取出表中的所有列名已经实现select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='RJProduct') 现在想把所有列明绑定到dropdpwnlst中,问题有一个,就是这个表中的列是不确定的是随时增加的,这个绑定怎么实现?求代码。

解决方案 »

  1.   

    动态就动态呗,完全不影响啊,你取出的列名就是
    select name  from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='RJProduct') 
    红色的部分。绑定你指定是name字段就行了,里面多少个元素你不用考虑的
    DataSet  ds  = XXX("你的SQL语句");
    this.DropDownList1.DataSource = ds;
    this.DropDownList1.DataTextField = "name";
    this.DropDownList1.DataValueField = "name";
    this.DropDownList1.DataBind();
    就OK啦,你多虑啦
      

  2.   

    跟你的sql语句没什么关系的.指定datatextfield ,datavaluefield就可以啦
      

  3.   

    refer:
    http://www.cnblogs.com/insus/archive/2011/11/08/2241255.html
      

  4.   

    既然所有列名已经得到了,那你试试用ArrayList建立一个对象,将所有列名放进去,你不说你的列会随机增加么,那增加的时候就ArrayList a=new ArrayList();a.add(列名);DropDownList.datasource=a;
    不过说实话,但愿你没把问题描述错,我真不知道你要绑定所有列干什么,一般都是需要一列下的所有值。
      

  5.   

    表名 列名都知道了,直接select [选中的列名] from RJProduc不就知道这一列内容了吗