|
 |
asp_databases thread: Verifying info in a database
Message #1 by KATHLEEN.M.WHALEN@c... on Fri, 23 Mar 2001 08:15:06 -0500
|
|
This is a multipart message in MIME format.
--=_alternative 0048C7BF85256A18_
Content-Type: text/plain; charset="us-ascii"
I have a page designed with a form for entering username and password
information. I'm vaguely familiar with working with databases and can set
up a page to add records to the database. In this case, however, I do not
want to add any data to the database, but actually compare and validate
the information with the data contained in a database. I am looking for
some code that will show me how to accomplish this. Can someone point me
in the right direction?
Thanks,
KMW
Message #2 by "Daniel O'Dorisio" <dodorisio@h...> on Fri, 23 Mar 2001 10:31:31 -0500
|
|
i do it like this:
open the db and grab the row that you wanna compare.
then do somthing like:
If objRS("field") <> str1compare Then addtoproblem "the value of strCompare
dosnt match the database value"
do this for each one you want to compare
then have a sub called addtoproblem that looks like this:
Dim Problem
Sub AddToProblem(buf)
If Problem <> "" Then Problem = Problem & "<br>"
Problem = Problem & buf
End Sub
then in the page do somthing like:
If problem <> "" Then
Response.Write Problem
End If
will that work??
Daniel
-----Original Message-----
From: KATHLEEN.M.WHALEN@c...
[mailto:KATHLEEN.M.WHALEN@c...]
Sent: Friday, March 23, 2001 6:01 PM
To: ASP Databases
Subject: [asp_databases] Verifying info in a database
This is a multipart message in MIME format.
--=_alternative 0048C7BF85256A18_
Content-Type: text/plain; charset="us-ascii"
I have a page designed with a form for entering username and password
information. I'm vaguely familiar with working with databases and can set
up a page to add records to the database. In this case, however, I do not
want to add any data to the database, but actually compare and validate
the information with the data contained in a database. I am looking for
some code that will show me how to accomplish this. Can someone point me
in the right direction?
Thanks,
KMW
Message #3 by KATHLEEN.M.WHALEN@c... on Tue, 27 Mar 2001 11:37:45 -0500
|
|
It's not working, but I think that's because I don't have objRS defined as
an object.
Not exactly sure what I need to do.
Message #4 by "Daniel O'Dorisio" <dodorisio@h...> on Tue, 27 Mar 2001 11:38:25 -0500
|
|
yeah.. that would cause a problem
use the following code:
dim objRS
dim connstring
connstring = ole db connection string here.
set objRS = Server.Createobject("ADODB.Recordset")
objRS.Open "SELECT <columns> FROM <table> WHERE <clause>", Connstring,
adOpenKeyset, adLockOptimistic
If objRS("field") <> str1compare Then
addtoproblem "the value of strCompare dosnt match the database value"
End If
' do this for each one you want to compare
objRS.close
set objRS = nothing
' then have a sub called addtoproblem that looks like this:
Dim Problem
Sub AddToProblem(buf)
If Problem <> "" Then Problem = Problem & "<br>"
Problem = Problem & buf
End Sub
'then in the page do somthing like:
If problem <> "" Then
Response.Write Problem
End If
this should work... let me know if it dosnt.
Daniel
-----Original Message-----
From: KATHLEEN.M.WHALEN@c...
[mailto:KATHLEEN.M.WHALEN@c...]
Sent: Tuesday, March 27, 2001 11:38 AM
To: ASP Databases
Subject: [asp_databases] RE: Verifying info in a database
Importance: High
It's not working, but I think that's because I don't have objRS defined as
an object.
Not exactly sure what I need to do.
Message #5 by "Ken Schaefer" <ken@a...> on Wed, 28 Mar 2001 13:50:53 +1000
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: yeah.. that would cause a problem
:
: use the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think your code has some problems.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: dim objRS
: dim connstring
: connstring = ole db connection string here.
: set objRS = Server.Createobject("ADODB.Recordset")
:
: objRS.Open "SELECT <columns> FROM <table> WHERE <clause>", Connstring,
: adOpenKeyset, adLockOptimistic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You allocate your connection string to a variable - good.
You don't allocate your SQL string to a variable - bad
You use adOpenKeySet, adLockOptimistic?
Why not adOpenForwardOnly, adLockReadOnly, adCmdText
?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If objRS("field") <> str1compare Then
: addtoproblem "the value of strCompare dosnt match the database value"
: End If
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why not just write this into the SELECT statement in the first place as
criteria? If there are no records returned, then there is no match...if
there are records returned, there is match.
OK, Kathleen wants a login script by the looks of things:
<%
Dim strUserName ' as string
Dim strPassword ' as string
Dim strSQL ' as string
Dim objConn ' as ADODB.Connection
Dim objRS ' as ADODB.Recordset
strUserName = Request.Form("UserName")
strPassword = Request.Form("Password")
strUserName = Replace(strUserName, "'", "''")
strPassword = Replace(strPassword, "'", "''")
strSQL = _
"SELECT " & _
" UserID " & _
"FROM " & _
" Users " & _
"WHERE " & _
" UserName = '" & strUserName & "' " & _
"AND " & _
" UserPassword = '" & strUserPassword & "'"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open Application("strDBConnection")
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If objRS.EOF then
' no match
Else
' there is a match
End if
objRS.close
Set objRS = nothing
objConn.close
Set objConn = nothing
%>
Cheers
Ken
Message #6 by "Jason Tienor" <jtienor@m...> on Tue, 27 Mar 2001 11:53:57 -0600
|
|
------=_NextPart_001_0000_01C0B6B4.9AD80230
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Does anyone know if it is possible to delete a text file using the filesy
stem object in the session onclose event in the global.asa? Any help wou
ld be great.
Thanks to all,
Jason L. Tienor
Interactive SolutionZ, LLC
jtienor@i...<br clear=3Dall><hr>Get your FREE downloa
d of MSN Explorer at <a href=3D"http://explorer.msn.com">http://explorer.
msn.com</a><br></p>
Message #7 by "Daniel O'Dorisio" <dodorisio@h...> on Wed, 28 Mar 2001 06:32:02 -0500
|
|
I was thinking she wants to modify the data after she gets it... so that's
why I used adOpenKeyset and adLockOptimistic.
didn't know putting stuff in variables helped.... thanks for the tip though.
not sure why I didn't put the compare in the select statement. I was
thinking that she wanted to compare several things. but I guess if she did
that could still be put in the select statement.. huh?
thanks for correcting me
Daniel
-----Original Message-----
From: Ken Schaefer [mailto:ken@a...]
Sent: Tuesday, March 27, 2001 10:51 PM
To: ASP Databases
Subject: [asp_databases] RE: Verifying info in a database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: yeah.. that would cause a problem
:
: use the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think your code has some problems.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: dim objRS
: dim connstring
: connstring = ole db connection string here.
: set objRS = Server.Createobject("ADODB.Recordset")
:
: objRS.Open "SELECT <columns> FROM <table> WHERE <clause>", Connstring,
: adOpenKeyset, adLockOptimistic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You allocate your connection string to a variable - good.
You don't allocate your SQL string to a variable - bad
You use adOpenKeySet, adLockOptimistic?
Why not adOpenForwardOnly, adLockReadOnly, adCmdText
?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If objRS("field") <> str1compare Then
: addtoproblem "the value of strCompare dosnt match the database value"
: End If
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why not just write this into the SELECT statement in the first place as
criteria? If there are no records returned, then there is no match...if
there are records returned, there is match.
OK, Kathleen wants a login script by the looks of things:
<%
Dim strUserName ' as string
Dim strPassword ' as string
Dim strSQL ' as string
Dim objConn ' as ADODB.Connection
Dim objRS ' as ADODB.Recordset
strUserName = Request.Form("UserName")
strPassword = Request.Form("Password")
strUserName = Replace(strUserName, "'", "''")
strPassword = Replace(strPassword, "'", "''")
strSQL = _
"SELECT " & _
" UserID " & _
"FROM " & _
" Users " & _
"WHERE " & _
" UserName = '" & strUserName & "' " & _
"AND " & _
" UserPassword = '" & strUserPassword & "'"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open Application("strDBConnection")
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If objRS.EOF then
' no match
Else
' there is a match
End if
objRS.close
Set objRS = nothing
objConn.close
Set objConn = nothing
%>
Cheers
Ken
|
|
 |