Private Sub cmdOK_Click()
Dim mrc As ADODB.Recordset
Dim strmsg As String
txtSQL = "select uid from userinfo where UID='" & Trim(txtUserName.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, strmsg)
If mrc.EOF = True Then
MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
UserName = mrc.Fields(0)
txtSQL = "select UID from userinfo where PWD='" & Trim(txtPassword.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, strmsg)
If mrc.EOF = True Then
MsgBox " 密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
OK = True
frmMain.Show
Unload Me
End Sub
CREATE TABLE [dbo].[userinfo] (
[UID] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[PWD] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[user_Des] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
Private Sub cmdOK_Click()
Dim mrc As ADODB.Recordset
Dim strmsg As String
txtSQL = "select uid from userinfo where UID='" & Trim(txtUserName.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, strmsg)
If mrc.EOF = True Then
MsgBox " 用户名错误!", vbExclamation + vbOKOnly, "警告"
txtUserName.SetFocus
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
Exit Sub
End If
UserName = mrc.Fields(0)
txtSQL = "select UID from userinfo where PWD='" & Trim(txtPassword.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, strmsg)
If mrc.EOF = True Then
MsgBox " 密码错误!", vbExclamation + vbOKOnly, "警告"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Exit Sub
End If
OK = True
frmMain.Show
Unload Me
End Sub
原帖由 .lemon. 于 2007-6-28 14:39 发表
...
SQL是不区别大小写的..
语法是成立的,但逻辑上有错误- -
找Uid为某某的Uid??
ps.一般有编译器环境做软件,报错,或结果有出入就跟踪一下啊.. 每步每步对照问题出在哪....
原帖由 tenshinx 于 2007-6-28 14:30 发表
我看了下。可能是这个错。
你压缩包里的userinfo这个表的建立sql是这个,注意黑体字
你的cmdok_Click事件下面的sql里是select uid from userinfo 大小写问题。
把txtSQL = "select uid from userinfo where UID='" & Trim(txtUserName.Text) & "'"这句里的uid改成UID(大写)试试
原帖由 蜡烛鞭三郎 于 2007-6-28 14:33 发表
txtSQL = "select UID "
txtSQL = txtSQL & " from userinfo "
txtSQL = txtSQL & "where UID ='" & Trim(txtUserName.Text) & "'"
SQL那段换一下就行了
LZ恶搞... Where语句里用UID Select后面跟 ...
Private Sub cmdOK_Click()
Dim mrc As ADODB.Recordset
Dim strmsg As String
txtSQL = "select count(*) from userinfo where UID='" & Trim(txtUserName.Text) & "' and PWD="'" & Trim(txtPassword.Text) & '"
Set mrc = ExecuteSQL(txtSQL, strmsg)
Dim return_count
return_count=mrc.Fields(0)
if return_count=0 then
MsgBox " 用户名不存在或密码错误!", vbExclamation + vbOKOnly, "警告"
end if
OK = True
frmMain.Show
Unload Me
End Sub
txtSQL = "select count(*) from userinfo where UID='" & Trim(txtUserName.Text) & "' and PWD='" & Trim(txtPassword.Text) & "'"
Dim mrc As ADODB.Recordset
Dim strmsg As String
txtSQL = "select count(*) from userinfo where UID='" & Trim(txtUserName.Text) & "' and PWD='" & Trim(txtPassword.Text) & "'"
mrc = ExecuteSQL(txtSQL, strmsg)
Dim return_count
return_count = mrc.Fields(0)
If return_count = 0 Or return_count = "0" Then
MsgBox(" 用户名不存在或密码错误!", vbExclamation + vbOKOnly, "警告")
End If
OK = True
frmMain.Show()
Unload(Me)
If return_count = 0 Or return_count = "0" Then
原帖由 蜡烛鞭三郎 于 2007-6-28 16:08 发表
ExecuteSQL没有封装
在MOD模块里
Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB. ...
原帖由 .lemon. 于 2007-6-28 16:10 发表
回28楼..
你在国内市场上买的无论哪一款SQL2000 or 2005. 在默认设置下,是绝对不区别大小写的.
你有这种情况,只能说是特例.. 要么你的环境特别设置过,要么日文版的问题.
原帖由 tenshinx 于 2007-6-28 16:08 发表
来。关于区分大小写问题,我们补充一个基本知识。
关于区分大小写问题,sqlserver是可以区分的,默认是不区分。
那么怎么样做到可以区分呢?
我们在create table时经常会碰到这样的语句,例如:CityName nv ...
原帖由 .lemon. 于 2007-6-28 16:10 发表
回28楼..
你在国内市场上买的无论哪一款SQL2000 or 2005. 在默认设置下,是绝对不区别大小写的.
你有这种情况,只能说是特例.. 要么你的环境特别设置过,要么日文版的问题.
原帖由 .lemon. 于 2007-6-28 16:22 发表
不想扯这个问题了..
翻baidu我也会..
SQL在安装的时候是有一个大小敏感的问题..
之前教我软件的那人给过我一个先入为主的概念,即,SQL类VB语言在默认情况下不区别大小写..
原帖由 蜡烛鞭三郎 于 2007-6-28 15:32 发表
字段名和表名怎么会不区分大小写呢.. 又不是SQL命令
你userinfo 这个表里的UID字段是大写的话
Select uid form userinfo 这句在分析器里是报错的..
欢迎光临 浆糊论坛-RO小站 (http://bbs.rohome.cn/) | Powered by Discuz! 7.2 |