如何让数据库的信息在listbox中显示
"Provider=SQLOLEDB;Data Source=5DA4929020BF4AA;integrated security=SSPI;Initial Catalog=yzx"这是数据库连接部分
能不能发给我在窗体加载时把数据显示在listbox 中的代码
这是数据查询部分"select * from num"
Option Explicit
Private Sub Form_Load()
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCon As String
strCon = "Provider=SQLOLEDB;Data Source=127.0.0.1;initial catalog=Northwind;User ID=sa;Password=admin"
con.ConnectionString = strCon
con.Open
rs.CursorLocation = adUseClient
rs.LockType = adLockReadOnly
rs.CursorType = adOpenForwardOnly
rs.Open "select OrderID from Orders", con, , , adCmdText
Dim iRecord As Long
For iRecord = 0 To rs.RecordCount - 1
List1.AddItem rs.Fields("OrderID").Value
rs.MoveNext
Next
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
End Sub