Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Can anyone tell me why my select statement is not case sensitve regarding the usrPassword=strPassword? Below are my codes:

 

Dim strUser, strPassword As String

Dim recLength, recCounter As Integer

Dim usrDataset As New DataSet()

strUser = txtUserName.Text

strPassword = txtPassword.Text

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\...\schUser.mdb;"

Dim cn As New OleDbConnection(strConn)

cn.Open()

Dim cmd As OleDbCommand = cn.CreateCommand()

Dim strSQL As String = "SELECT * FROM USERS WHERE usrName like " & "'" & strUser & "'" & " AND usrPassword=" & "'" & strPassword & "'"

cmd.CommandText = strSQL

Dim intRecordMatched As String = cmd.ExecuteScalar

If intRecordMatched <> Nothing Then

cn.Close()

Me.Close()

Exit Sub

Else

MsgBox("Incorrect Password or User Name", MsgBoxStyle.Critical)

End If

Please help.

 

Many thanks in advance.

 

Chong

 

:confused:

  • *Experts*
Posted

With a default installation, all columns in SQL Server are not case-sensitive. This is set by Collation and can be overridden.

 

For instance, on your USERS table you probably have the collation set to SQL_Latin1_General_CP1_CI_AS. Check it by using Enterprise Manager, right click on the table and select Design. The last property for a column will be the collation. All values that have "...CI..." are case-insensitive. So change

SQL_Latin1_General_CP1_CI_AS

to

SQL_Latin1_General_CP1_CS_AS

 

and your usrPassword column will be case-sensitive.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

I'm not sure if you can change the Collation (or anything equivalent) in Access, but you can use the StrComp function to do binary compares (case-sensitive):

-- Below will match "hello" but not "Hello" or "heLLO"
SELECT * FROM Table1 where StrComp(test, 'hello', 0) = 0

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

First, thanks for responding. So for my select statment it will be something like this?

 

Dim strSQL As String = "SELECT * FROM USERS WHERE usrName like " & "'" & strUser & "'" & " AND StrComp(usrPassword, 'strPassword',0)

 

The concern I have is because my strPassword is a variable that hold a string so how would I specify that in the StrComp function?

 

Thanks!

 

Chong

Posted

Dim strPassword As String = "Test"

Dim strSQL As String = "SELECT * FROM USERS WHERE usrName like " & "'" & strUser & "'" & " AND StrComp(usrPassword, '" & strPassword & "',0) = 0"

 

Andy

Code today gone tomorrow!
  • 3 months later...
  • *Experts*
Posted

Are you using Access?

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

The function StrConv doesn't work in SQL Server. As stated above, you'll have to change the collation in SQL Server as by default, all columns are case-insensitive. I can't think of a way to do a case-sensitive search if you want the column to remain case-insenstive.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
Looking at the MS SQL Server, I can not find the Collation. After opening up the table in design mode, its not one of the properties for the columns. Is there a way I can be case-sensitive on a select statment without iterating through the Dataset after the fact and deleting the unwanted information? Any ideas?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...