求童鞋帮我看下这个程序,关于ADo的排序问题。。
Option ExplicitDim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim cnnDB As ADODB.Connection
Dim rs2 As New ADODB.Recordset
Private Sub Form_Load()
rs2.LockType = adLockOptimistic
rs2.CursorType = adOpenKeyset
rs2.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
Set rs1 = New ADODB.Recordset
rs1.Open "select * from sheet1", cn, adOpenForwardOnly, adLockReadOnly, adCmdText
rs2.Open "SELECT ×Ö¶Î5 From sheet1 GROUP BY ×Ö¶Î5 ORDER BY ×Ö¶Î5", cn, adOpenDynamic
Combo1.Clear
Combo2.Clear
rs1.MoveFirst
If Not rs1.EOF Then
rs1.MoveFirst
Do While Not rs1.EOF
Combo2.AddItem rs1!×Ö¶Î6
rs1.MoveNext
Loop
End If
rs2.MoveFirst
If Not rs2.EOF Then
rs2.MoveFirst
Do While Not rs2.EOF
Combo1.AddItem rs2!×Ö¶Î5
rs2.MoveNext
Loop
End If
Set cnnDB = New ADODB.Connection
cnnDB.Open "Provider=Microsoft.jet.OLEDB.4.0;Data source=" & VB.App.Path & "\db1.mdb"
'adodcµÄÁ¬½Ó×Ö·û´®
Adodc1.ConnectionString = cnnDB.ConnectionString
' Ö¸¶¨Command¶ÔÏóµÄÐÎ̬
Adodc1.CommandType = adCmdTable
' ÉèÖô«»ØÒ»¸ö×ÊÁϼ¼¯¡£
Adodc1.RecordSource = "sheet1"
Set DataGrid1.DataSource = Adodc1
DataGrid1.RecordSelectors = True
End Sub
Private Sub Combo1_Click()
rs1.Filter = "×Ö¶Î5 = '" & Combo1.Text & "'"
Combo2.Clear
Combo2.Text = rs1!×Ö¶Î6
rs1.MoveFirst
Do While Not rs1.EOF
Combo2.AddItem rs1!×Ö¶Î6
rs1.MoveNext
Loop
End Sub
Private Sub Combo2_Click()
Adodc1.Recordset.Filter = "×Ö¶Î6 = '" & Combo2.Text & "'and ×Ö¶Î5= '" & Combo1.Text & "'"
Text1.Text = Adodc1.Recordset.RecordCount
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs1.Close
rs2.Close
Set rs1 = Nothing
Set rs2 = Nothing
End Sub
这个是代码
目的是。。。读取 对 字段6 中的统计 次数 进行排序。。。
毕业设计 卡这 了 求童鞋,叔叔 大神们帮个忙 --------------------编程问答-------------------- 乱码+无意义的用户名。
你这是让人家从你拉的易做图中猜你今天吃了什么。 --------------------编程问答-------------------- 乱码+无意义的用户名。
=〉
乱码+无意义的变量名。 --------------------编程问答--------------------
哈哈,这个说法绝了 --------------------编程问答-------------------- --------------------编程问答-------------------- Option Explicit
Dim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Private Sub Form_Load()
rs2.LockType = adLockOptimistic
rs2.CursorType = adOpenKeyset
rs2.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
Set rs1 = New ADODB.Recordset
rs1.Open "SELECT ×Ö¶Î5 From sheet1 GROUP BY ×Ö¶Î5 ORDER BY ×Ö¶Î5", cn
Combo1.Clear
Do While Not rs1.EOF
Combo1.AddItem rs1!×Ö¶Î5
rs1.MoveNext
Loop
rs1.Close
If Combo1.ListCount Then Combo1.ListIndex = 0 'This statement triggers Combo1_Click
'adodcµÄÁ¬½Ó×Ö·û´®
Adodc1.ConnectionString = cnn.ConnectionString
' Ö¸¶¨Command¶ÔÏóµÄÐÎ̬
Adodc1.CommandType = adCmdTable
' ÉèÖô«»ØÒ»¸ö×ÊÁϼ¼¯¡£
Adodc1.RecordSource = "sheet1"
Set DataGrid1.DataSource = Adodc1
DataGrid1.RecordSelectors = True
End Sub
Private Sub Combo1_Click()
rs1.Open "select * from sheet1 WHERE ×Ö¶Î5 = '" & Combo1.Text & "'"
Combo2.Clear
Do While Not rs1.EOF
Combo2.AddItem rs1!×Ö¶Î6
rs1.MoveNext
Loop
rs1.Close
If Combo2.ListCount Then Combo2.ListIndex = 0
End Sub
Private Sub Combo2_Click()
Adodc1.Recordset.Filter = ""
Adodc1.Recordset.Filter = "×Ö¶Î6 = '" & Combo2.Text & "'and ×Ö¶Î5= '" & Combo1.Text & "'"
Adodc1.Recordset.MoveLast
Adodc1.Recordset.MoveFirst
Text1.Text = Adodc1.Recordset.RecordCount
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs1.Close
rs2.Close
Set rs1 = Nothing
Set rs2 = Nothing
End Sub
--------------------编程问答-------------------- Private Sub Combo2_Click()
Adodc1.Recordset.Filter = ""
Adodc1.Recordset.Filter = "×Ö¶Î6 = '" & Combo2.Text & "'and ×Ö¶Î5= '" & Combo1.Text & "'"
Adodc1.Recordset.MoveLast
Adodc1.Recordset.MoveFirst
Text1.Text = Adodc1.Recordset.RecordCount
End Sub
这句话报错了不知道怎么个原因、、少了什么东西么 --------------------编程问答-------------------- 这是一段话啊,报得什么错? --------------------编程问答-------------------- Adodc1.Recordset.Filter = "×Ö¶Î6 = '" & Combo2.Text & "' And ×Ö¶Î5= '" & Combo1.Text & "'" --------------------编程问答--------------------
这个还是不行 只有这句话还是报错 不知道为什么了。。。 --------------------编程问答-------------------- 你的字段都是什么类型的?数字的就不要加单引号 --------------------编程问答-------------------- Adodc1.Recordset.Filter = "×Ö¶Î6 = '" & Combo2.Text & "' And ×Ö¶Î5= '" & Combo1.Text & "'"
这里加个断点, 然后debug.print Adodc1.Recordset.Filter看看你的筛选语句到底是什么吧.
补充:VB , 数据库(包含打印,安装,报表)