VB+SQL SERVER 总是出现列名无效

来源:百度知道 编辑:UC知道 时间:2024/05/26 01:08:00
Dim rs_dl As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim sql As String

If Text1.Text = "" Then
MsgBox "用户名不能为空,请重新输入!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "密码不能为空,请重新输入!", vbInformation + vbOKOnly, "提示"
Exit Sub
End If

cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=database;Data Source=SUNXP-7BDB3E6B1"
sql = "select * from UserInfo where 用户名=""" & Text1.Text & """"
rs_dl.Open sql, cn, adOpenStatic, adLockBatchOptimistic

If Not rs_dl.EOF Then
If rs_dl("密码") = Text2.Text Then
If rs_dl("管理员") = True Then
GL
End If
If rs_dl("操作员") = True Then
CZ
End If
Else
MsgBox &quo

sql = "select * from UserInfo where 用户名=""" & Text1.Text & """"

你改一下:

sql = "select * from UserInfo where 用户名='" & Text1.Text.Trim() & "'"

我觉得列名无效估计问题出在
sql = "select * from UserInfo where 用户名=""" & Text1.Text & """"
这个用户名上,后面如果错了,最多就是找不到,