5

返回成功

Dim user = "ravi"
        Dim pass = "admin"
        objcmd.CommandText = "Select * from ADMIN_INFO where ADMIN_ID='" & user & "' and ADMIN_PASS='" & pass & "'"

返回成功

Dim user = "ravi"
        Dim pass = "ADMIN"
        objcmd.CommandText = "Select * from ADMIN_INFO where ADMIN_ID='" & user & "' and ADMIN_PASS='" & pass & "'"

执行查询后,两者都返回成功,其中仅在表raviadmin可用。那么,我如何检查是否区分大小写。需要帮忙 !!

4

2 回答 2

2
CREATE TABLE #temp
(
    Password Varchar(2)
)
insert into #temp values('a')

第一种方法

select Password  from #temp Where Password COLLATE Latin1_general_CS_AS  = 'A' 
select Password  from #temp Where Password COLLATE Latin1_general_CS_AS  = 'a' 

第二种方法

select Password  from #temp Where cast(Password as varbinary(2))  = cast('A' as varbinary(15)) 
select Password  from #temp Where cast(Password as varbinary(2))  = cast('a' as varbinary(15)) 

drop table #temp
于 2012-04-05T17:51:49.673 回答
2

本文可能会对您有所帮助:SQL Server 查询中区分大小写的搜索。但是,一开始就将密码保存为纯文本通常不是一个好习惯。

此外,您可以只从数据库中选择管理员行,然后在 .Net 端进行密码比较,默认情况下比较区分大小写。

bool result = string1.Equals(string2); //this is case sensitive unless you specify otherwise
于 2012-04-05T17:58:46.047 回答