VB编程,用Combox把ACCESS中的字段做成下来菜单。
在VB中用ADO连接ACCESS数据库,之后读取某一字段的内容,并在VB中用Combox做成下拉菜单,但是在Combox一直是显示前面两个记录??而且记录集的Record...
在VB中用ADO连接ACCESS数据库,之后读取某一字段的内容,并在VB中用Combox做成下拉菜单,但是在Combox一直是显示前面两个记录??而且记录集的RecordCount还是负数?这是怎么回事?程序如下:
Option Explicit
Public DBCnn As New ADODB.Connection
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
Dim SqlM, SqlStr As String
Dim i As Integer
SqlStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb;Persist Security Info=False"
SqlM = "select rate from material"
DBCnn.open SqlStr
rs.open SqlM, DBCnn
If Abs(rs.RecordCount) > 0 Then
rs.MoveFirst
For i = 0 To Abs(rs.RecordCount)
comMaterial.AddItem rs.Fields("rate")
rs.MoveNext
Next
End If
End Sub 展开
Option Explicit
Public DBCnn As New ADODB.Connection
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
Dim SqlM, SqlStr As String
Dim i As Integer
SqlStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb;Persist Security Info=False"
SqlM = "select rate from material"
DBCnn.open SqlStr
rs.open SqlM, DBCnn
If Abs(rs.RecordCount) > 0 Then
rs.MoveFirst
For i = 0 To Abs(rs.RecordCount)
comMaterial.AddItem rs.Fields("rate")
rs.MoveNext
Next
End If
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询