R
Rob Meade
Hi all,
We've just started using ASP.Net at work, and whilst I have several years of
regular ASP experience, I am struggling to get a good foot hold with .net...
My current query is with the following code :
If objDataReader.Read() Then
' strUserID = objDataReader("UserID")
' strForename = objDataReader("Forename")
' strSurname = objDataReader("Surname")
' Label4.Text = "STEP 1 " & strUserID & " " & strForename & " " &
strSurname
While objDataReader.Read()
strUserID = objDataReader("UserID")
strForename = objDataReader("Forename")
strSurname = objDataReader("Surname")
Label4.Text = "STEP 2 " & strUserID & " " & strForename & " " &
strSurname
End While
Else
Label4.Text = "No user found"
End If
I have a small test page where I am trying to get a user to enter a
username/password, click login and then the code runs off to the database,
this is so far working - however, to ensure that I returned a recordset (ie,
a user was found) then I added the If objDataReader.Read() Then code - what
I have found though is that if there is only ONE user in the database with
the username then it will use the code above but doesn't do anything - if I
uncomment the commented code - it will work using the top bit, however, if I
place a second user in the database with the same username, then it ignores
the top bit and uses the While objDataReader.Read() loop....and obviously
overwrites the label with the second users details...
I'd assumed that the code was doing this :
go get me a recordset
is there anyone in it?
If there is, then iterate through and plonk their details in the label
But that doesnt seem to be the case - I dont understand why I've had to
duplicate code to get this to work - I'm clearly doing something
incorrectly, but I have no idea why..
If I enter a username that isnt in the database, it correctly displays the
"No user found" message, its only when it finds one or more users with the
same username that I seem to have problems....
Any help would be gratefully received, and please be gently - this is all
VERY taxing at the moment!
Regards
Rob
We've just started using ASP.Net at work, and whilst I have several years of
regular ASP experience, I am struggling to get a good foot hold with .net...
My current query is with the following code :
If objDataReader.Read() Then
' strUserID = objDataReader("UserID")
' strForename = objDataReader("Forename")
' strSurname = objDataReader("Surname")
' Label4.Text = "STEP 1 " & strUserID & " " & strForename & " " &
strSurname
While objDataReader.Read()
strUserID = objDataReader("UserID")
strForename = objDataReader("Forename")
strSurname = objDataReader("Surname")
Label4.Text = "STEP 2 " & strUserID & " " & strForename & " " &
strSurname
End While
Else
Label4.Text = "No user found"
End If
I have a small test page where I am trying to get a user to enter a
username/password, click login and then the code runs off to the database,
this is so far working - however, to ensure that I returned a recordset (ie,
a user was found) then I added the If objDataReader.Read() Then code - what
I have found though is that if there is only ONE user in the database with
the username then it will use the code above but doesn't do anything - if I
uncomment the commented code - it will work using the top bit, however, if I
place a second user in the database with the same username, then it ignores
the top bit and uses the While objDataReader.Read() loop....and obviously
overwrites the label with the second users details...
I'd assumed that the code was doing this :
go get me a recordset
is there anyone in it?
If there is, then iterate through and plonk their details in the label
But that doesnt seem to be the case - I dont understand why I've had to
duplicate code to get this to work - I'm clearly doing something
incorrectly, but I have no idea why..
If I enter a username that isnt in the database, it correctly displays the
"No user found" message, its only when it finds one or more users with the
same username that I seem to have problems....
Any help would be gratefully received, and please be gently - this is all
VERY taxing at the moment!
Regards
Rob