Dim Fc As Integer
Dim rc As Integer
Dim tf As Boolean
tf = False
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;" & "Data Source=xixi"
cn.Open
cn.CursorLocation = adUseClient
Set rs = cn.Execute("select * from pass")
If rs.EOF And rs.BOF Then '
MsgBox "没有用户!", vbOKOnly, "提示"
cn.Close
Exit Sub
Else
rs.MoveFirst
Do While Not rs.EOF
If Text1.Text = rs.Fields(0).Value And Text2.Text = rs.Fields(1).Value Then
' MsgBox "ok!"
tf = True
Exit Do
End If
rs.MoveNext
Loop
End If
If tf = False Then
MsgBox "用户名或密码有误!", vbOKOnly, "提示"
cn.Close
Exit Sub
ElseIf tf = True Then
form1.Hide
Form2.Show
End If
为什么输入正确时
为什么form2不能显示
Dim rc As Integer
Dim tf As Boolean
tf = False
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;" & "Data Source=xixi"
cn.Open
cn.CursorLocation = adUseClient
Set rs = cn.Execute("select * from pass")
If rs.EOF And rs.BOF Then '
MsgBox "没有用户!", vbOKOnly, "提示"
cn.Close
Exit Sub
Else
rs.MoveFirst
Do While Not rs.EOF
If Text1.Text = rs.Fields(0).Value And Text2.Text = rs.Fields(1).Value Then
' MsgBox "ok!"
tf = True
Exit Do
End If
rs.MoveNext
Loop
End If
If tf = False Then
MsgBox "用户名或密码有误!", vbOKOnly, "提示"
cn.Close
Exit Sub
ElseIf tf = True Then
form1.Hide
Form2.Show
End If
为什么输入正确时
为什么form2不能显示
解决方案 »
- o, 发现了一个免费视频资源网,与大家共享!
- 求助VB表格的存储?
- 动态加载控件的问题!
- check控件enable=false后,底色变成灰的,如何才能变成其它颜色?
- 终于见到大伙了,散分!!
- 用OLE如何在VB中调用Powerpoint文档?
- 绝佳的报表打印控件,需要的人留个Mail
- 关于activex控件,请朋友们指点
- 您还为做报表发愁吗?试试坏猫报表打印控件吧!
- 用Data连接数据库,设置DatabaseName为access文件(d:\proj\proj\exam.mdb),为什么设置RecordSource出错?
- 请问VB里面有没有函数可以取得当前操作系统windows或其下一级system32的目录?
- Rnd * 10有否可能产生0?
2、或改成这样用:Set rs = cn.Execute("select 用户名,密码 from pass")
写得太复杂了啊。
Set rs = new adodb.recordset
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;" & "Data Source=xixi"
cn.Open
rs.CursorLocation = adUseClient
rs.open "select password from pass where 存用户名那个字段='" & text1.text & "'",cn
If rs.EOF And rs.BOF Then '
MsgBox "没有用户!", vbOKOnly, "提示"
else
if text2.text = rs.fields("password") then
form1.Hide
Form2.Show
else
MsgBox "用户名或密码有误!", vbOKOnly, "提示"
End If
end if
rs.close
cn.close
dim islogin as boolean
islogin=false
rs.open "select * from pass where username='用户名' and pass='密码'",conn,3,2
if not rs.eof then
msgbox "ok"
islogin=true
else
msgbox "bad"
end if
rs.close
conn.close
if islogin then
form1.visible=false
form2.show 1
end if
改成这样吧:
dim sql as string
sql="select * from pass where 用户名='"& text1.text &"' and 密码='"& text2.text &"'"
rs.open sql,cn
If rs.EOF Then '
MsgBox "密码错误或者用户名不对!", vbOKOnly, "提示"
rs.Close
set rs=nothing
Exit Sub
Else
rs.Close
set rs=nothing
form1.Hide
Form2.Show
End If
Dim rc As Integer
Dim tf As Boolean
tf = False
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;" & "Data Source=xixi"
cn.Open
cn.CursorLocation = adUseClient
set rs =new ADODB.RecordSet
rs.open "select * from pass",cn,adOpenDynamic,adLockReadOnly
If rs.EOF = True then
MsgBox "没有用户!", vbOKOnly, "提示"
rs.Close
cn.Close
Exit Sub
end if
Do Until rs.EOF
If Text1.Text = rs.Fields!user And Text2.Text = rs.Fields!pass Then
MsgBox "ok!"
tf = True
Exit Do
End If
rs.MoveNext
tf=false
Loop
rs.close If tf = False Then
MsgBox "用户名或密码有误!", vbOKOnly, "提示"
Else
form1.Hide
Form2.Show
End If
Dim Fc As Integer
Dim rc As Integer
Dim tf As Boolean
tf = False
cn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;" & "Data Source=xixi"
cn.Open
cn.CursorLocation = adUseClient
Set rs = cn.Execute("select 用户名,密码 from pass where 用户名='" & Text1.Text & "'" ")
If rs.EOF And rs.BOF Then '
MsgBox "没有用户!", vbOKOnly, "提示"
cn.Close
Exit Sub
Else
If Text1.Text = rs.Fields(0).Value And Text2.Text = rs.Fields(1).Value Then
MsgBox "ok!"
tf = True
else
tf = false
End If
End If
If tf = False Then
MsgBox "用户名或密码有误!", vbOKOnly, "提示"
cn.Close
Exit Sub
ElseIf tf = True Then
form1.Hide
Form2.Show
End If
把所有的rs.fields用Trim过滤一下,可能存在空格,然后再进行比较
把你自己的rs.Fields(1).Value全换成Trim(rs.Fields(1).Value)
If Text1.Text = rs.Fields(0).Value And Text2.Text = rs.Fields(1).Value
这句的问题
你看记录集第一个字段和第2个字段分别对应用户名和密码吗?
这个需要你设断点,单步调试下
另外你这个程序的确是效率太低了,何必要这么写呢?
直接
select * from pass where 用户名='"& text1.text &"' and 密码='"& text2.text &"'
然后看返回的记录数是否>0如果是就通过认证了,根本不需要用到循环的
你可以参考pweixing(幸运米,幸运得米!) 写的。
你可以把sql这么写
select * from pass where 用户名='"& Trim(text1.text) &"' and 密码='"& Trim(text2.text) &"'
"myusername"<>"myusername "
这样注册的时候用户名是"12345678",而数据库里就是"12345678 "了
所以还是改数据库比较方便,大家给的语句都是非常好的