我想把access数据库中的课程全部连接到VB的list中,怎样写代码?急~ 20
1个回答
展开全部
试下下面的代码行不行,对ACCESS不熟悉,估摸着弄的,需要添加对ADO的引用
Private Sub LoadCourseName()
'db.mdb 数据库文件名
'courses 课程配置表名称
'name 课程名字段名称
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As Stream
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
SQL = "select * from courses"
rs.Open SQL, conn, 1, 2
If rs.RecordCount > 0 Then rs.MoveFirst
Do While Not (rs.EOF Or rs.BOF)
List1.AddItem rs.GetString("name")
rs.MoveNext
Loop
rs.Close
conn.Close
End Sub
Private Sub LoadCourseName()
'db.mdb 数据库文件名
'courses 课程配置表名称
'name 课程名字段名称
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As Stream
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
SQL = "select * from courses"
rs.Open SQL, conn, 1, 2
If rs.RecordCount > 0 Then rs.MoveFirst
Do While Not (rs.EOF Or rs.BOF)
List1.AddItem rs.GetString("name")
rs.MoveNext
Loop
rs.Close
conn.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询