如何将一个表中的所有列的列名全都列到ComboBox框中

解决方案 »

  1.   

    代码如下Sub ViewFields()
       Dim cnn As New ADODB.Connection
       Dim rst As New ADODB.Recordset
       Dim fld As ADODB.Field
       Dim cat As New ADOX.Catalog   ' Open the Connection
       cnn.Open _
          "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=c:\Program Files\Microsoft Office\" & _
          "Office\Samples\Northwind.mdb;"   ' Open the catalog
       Set cat.ActiveConnection = cnn   ' Set the Source for the Recordset
       Set rst.Source = cat.Views("AllCustomers").Command   ' Retrieve Field information
       rst.Fields.Refresh
       For Each fld In rst.Fields
          Debug.Print fld.Name & ":" & fld.Type
          '加入你的combobox控件
       NextEnd Sub
      

  2.   

    dim f as fieldFor Each f In rs.Fields
        combo1.additem f.name
    Next
      

  3.   

    rs.open "select * from table1 where 1=2",cn
    for i=1 to rs.fields.count
      combox.AddItem rs.fields(i).name
    next i
      

  4.   

    当然你也可以用OpenSchema方法来做
    请详细参阅ADO参考文档中OpenSchema