实时错误:对象名无效
我是用VB连接SQL server的,说对象名'combo1'无效,这是我的代码:Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rst As New ADODB.Recordset
Dim rct As New ADODB.Recordset
Private Sub Form_Load()
Dim i As Integer
cn.Open "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=database;Data Source=localhost"
cn.CursorLocation = adUseClient
rs.Open "select * from 中国", cn
If rs.RecordCount <> 0 Then
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs.Fields("省名")
rs.MoveNext
Next i
End If
rst.Open "select * from " & Trim(Combo1.Text) & "", cn
If rst.RecordCount <> 0 Then
rst.MoveFirst
For i = 0 To rst.RecordCount - 1
Combo2.AddItem rst.Fields("城市名")
rst.MoveNext
Next i
End If
rct.Open "select * from " & Trim(Combo2.Text) & "", cn
If rct.RecordCount <> 0 Then
rct.MoveFirst
For i = 0 To rct.RecordCount - 1
Combo3.AddItem rct.Fields("县名")
rct.MoveNext
Next i
End If
Combo1.Text = "选择省份"
Combo2.Text = "选择城市"
Combo3.Text = "选择县/区"
Text1.Text = ""
End Sub
画了控件的:
这是错误截图: