我想把数据库yuanliaochang的表user中的用户名username添加到cmbName中,cmbName的caption属性为用户名,我的数据库用的是sql server 2000,操作系统windows server 2003,计算机名为server。请问我以下的代码哪里不对啊?
Option Explicit
Dim sql As String
Dim conn As New ADODB.connection
Dim yuanliaochang As String
Dim user As String
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
Dim connectionstring As String
connectionstring = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=yuanliaochang;Data Source=SERVER"
conn.Open connectionstring
If conn.State <> 1 Then
conn.Open (connectionstring)
End If
Set rs = conn.Execute("select * from user")
With rs
.MoveFirst
Do While Not .EOF
DoEvents
cmbName.AddItem (!用户)
.MoveNext
Loop
End With
cmbName.ListIndex = 0
conn.Close
End Sub
提示是在关键字user附近有语法错误,Set rs = conn.Execute("select * from user")一行就变成黄的了,应该怎么改啊?
參考答案:Set rs = conn.Execute("select * from [user]")
user是关键字,使用时需要用方括号括上