|
-
Oct 22nd, 2003, 12:31 PM
#1
Thread Starter
Hyperactive Member
DataReader And SQL Server
VB Code:
Dim objConnection As New SqlClient.SqlConnection _
("server=.;database=ndbs;trusted_connection=true")
Dim objCommand As New SqlClient.SqlCommand _
("Select * From tblUsers", objConnection)
Dim objReader As SqlClient.SqlDataReader
' Open the database connection
objConnection.Open()
' Put the results in the DataReader object
objReader = objCommand.ExecuteReader
Do While objReader.Read
If objReader.Item("password") = "password" Then
Response.Write("The Password Is Password")
End If
Loop
objReader.Close()
objConnection.Close()
End Sub
The problem I have is that when I use the following :
VB Code:
If objReader.Item("password") = "password" Then
Response.Write("The Password Is Password")
End If
It just does not recognize that I am trying to compare the strings. It is so frustrating, if I do a response.write(objReader.Item("password")) whilst the datareader.read loop goes around then it does display the information that the DataReader pulls from the sql database.
Is it because the DataReader is read-only????
Any ideas?????
Cheers,
Matt.
-
Oct 22nd, 2003, 12:37 PM
#2
PowerPoster
Try calling the ToString() method before doing your comparison:
Code:
objReader.Item("password").ToString() == "Password"
Last edited by Lethal; Oct 22nd, 2003 at 01:28 PM.
-
Oct 22nd, 2003, 01:21 PM
#3
Frenzied Member
you should be able to do something like this as well.
Code:
If objReader["password"] = "password" Then
Response.Write("The Password Is Password")
End If
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 22nd, 2003, 02:58 PM
#4
The Microsoft-recommended way to do string comparisons is as follows:
if objReader.Item("password").toLower.CompareTo( "password") = 0 then
...
end if
Note that this compares the CONTENTS of the column. If that's what you want, then good.
If you were attempting to compare the column name, then you need to use (from memory, so I might be slightly off) objReader.columns("password").ColumnName
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Oct 23rd, 2003, 04:01 AM
#5
Thread Starter
Hyperactive Member
Thanks
Thanks for you help, just out of interest I had to do the following :
VB Code:
If Trim(objReader["password"].ToString) = "password" Then
Response.Write("The Password Is Password")
End If
Weird I thought, having use Trim, when using MS Access I have never had to do that.
Thanks a lot.
Matt.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|