有关sql execl表查询排序问题
诸位先生请教个问题,我在读取execl表时遇到一个编号相没有字段的问题。不知道如何查询排序,请大家指教。谢谢!如:select*from [sheel1$] order by A列 desc.如何写对A列编号进行排序?
Sub getFieldName() ‘this sub function can get the field name Dim RS As ADODB.Recordset Dim CN As ADODB.Connection Dim FN As ADODB.Field Set CN = New ADODB.Connection Set RS = New ADODB.Recordset CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access.mdb;Persist Security Info=False" RS.Open "Select * from Table1", CN For Each FN In RS.Fields List2.AddItem FN.Name Next RS.Close Set RS = Nothing CN.Close Set CN = Nothing End Sub
[此贴子已经被作者于2016-8-17 20:07编辑过]
Dim RS As New ADODB.Recordset Dim cn As New ADODB.Connection Dim XX As String cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=" & App.Path & "\ABCD.xls;Extended Properties='Excel 8.0;HDR=Yes'" RS.Open "Select * From [Sheel1$]", cn, 3, 2 XX = RS.Fields(0).Name '取得第一个字段的字段名称 RS.Close Set RS = Nothing RS.Open "Select * From [Sheel1$] Order BY " & XX & " Desc", cn, 3, 2 '以第一个字段从大到小排序,注意语句中必须的空格 Do While Not RS.EOF '这里是用控件显示排序后数据的代码 RS.MoveNext Loop RS.Close Set RS = Nothing cn.Close Set cn = Nothing
[此贴子已经被作者于2016-8-17 23:39编辑过]