Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Sub main()
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=E:\demo.xlsExtended Properties=Excel 8.0Persist Security Info=False"
cn.Open
cn.Execute "ALTER TABLE [Sheet1$] ADD COLUMN NewField long"
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.Open "SELECT * FROM [Sheet1$]"
Debug.Print rs.Fields(rs.Fields.Count - 1).Name
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
假定定义部分你都写好了。那么……
Dim RS as ADODB.RecordsetDim C as new Collection
'假定你连接数据库部分已经写好了
RS.Open "Select * From MyDB"
While Not RS.EOF
C.Add RS.Fields(1)
'或者
'C.Add RS!字段名
RS.MoveNext
Wend
RS.Close
随手写的,可能会有错,供参考。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)