Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: What is the solution?


Message #1 by ggebre@h... on Fri, 21 Jun 2002 14:37:32
Ken replied to my posting and mentioned to me where my problem is.  I 
would appreciate if someone could help me resolve this problem.  What is 
the best way to handle this problem,  how should I rewrite the code.

Your help is greatly appreciated. 
Thanks. 



Dim strUsers, objConn
:
: Set strUsers = Server.CreateObject("ADODB.Connection")
: 'objConn.Open Server.CreateObject("ADODB.RecordSet")
: 'rsUsers.Open Application("ADODB.ConnectionString")
:
:
: If Session("CustomerID") <> " " Then
: strUsers.Filter = "CutomerID = ' " & Session("CustomerID")
: & " ' "
: Else
: strUsers.Filter = "EmailAddress = '"  & Request.Form
: ("Email") & " '" & _
:                 "AND Password = '" & Request.Form
: ("Password") & " ' "
:    If strUsers.EOF Then
:    strUsers.AddNew
:   End If
:  End If
Message #2 by "Darrell" <darrell@b...> on Fri, 21 Jun 2002 20:48:36 +0100
Hi

I think you have got a few things mixed up, your statement "strUsers 
Server.CreateObject("ADODB.Connection")
should read:

 rsUsers = Server.CreateObject("ADODB.Recordset")

You also need to open your recordset connection:

rsUsers.Open "CustomerTable", objConn, adOpenForwardOnly, adLockOptimistic,
adCmdTable

I am assuming that objConn is a database connection from one of your include
files. Make sure that you also close your connections when you are finished
with them!

Now you can run your filter:

If Session("CustomerID") <> " " Then
	rsUsers.filter = "CutomerID = ' " &Session("CustomerID")& " ' "
etc etc

HTH
Cheers
Darrell



-----Original Message-----
From: ggebre@h... [mailto:ggebre@h...]
Sent: 21 June 2002 14:38
To: Access ASP
Subject: [access_asp] What is the solution?


Ken replied to my posting and mentioned to me where my problem is.  I
would appreciate if someone could help me resolve this problem.  What is
the best way to handle this problem,  how should I rewrite the code.

Your help is greatly appreciated.
Thanks.



Dim strUsers, objConn
:
: Set strUsers = Server.CreateObject("ADODB.Connection")
: 'objConn.Open Server.CreateObject("ADODB.RecordSet")
: 'rsUsers.Open Application("ADODB.ConnectionString")
:
:
: If Session("CustomerID") <> " " Then
: strUsers.Filter = "CutomerID = ' " & Session("CustomerID")
: & " ' "
: Else
: strUsers.Filter = "EmailAddress = '"  & Request.Form
: ("Email") & " '" & _
:                 "AND Password = '" & Request.Form
: ("Password") & " ' "
:    If strUsers.EOF Then
:    strUsers.AddNew
:   End If
:  End If

Message #3 by "Ken Schaefer" <ken@a...> on Mon, 24 Jun 2002 13:16:10 +1000
What you need is to map out the logic before you start writing the code:

a) Open a connection object
b) Return a recordset
c) If there are no matching records, then create a new record
d) If there are matching records then ---do xxx----

<%
Dim objConn        ' ADODB.Connection
Dim obJRS          ' ADODB.Recordset
Dim strSQL         ' String
Dim strUserName ' String
Dim strUserPassword ' String

strUserName = Request.Form("txtUserName")
strUserPassword = Request.Form("txtUserPassword")

strSQL = _
    "SELECT UserName, UserPassword " & _
    "FROM Users " & _
    "WHERE UserName = '" & SafeSQL(strUserName) & "' " & _
    "AND UserPassword = '" & SafeSQL(strUserPassword) & "'"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open Application("DBConnString")
' Put your own DB conn string on the line above

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn

If objRS.EOF then
    ' Create SQL statement to INSERT a new record
Else
    ' User already exists
End If

Call objDispose(objRS, True, True)
Call objDispose(objConn, True, True)

Sub objDispose( _
    ByRef objToDispose, _
    ByVal blnClose, _
    ByVal blnNothing _
    )

    If blnClose then
        objToDispose.Close
    End If

    If blnNothing then
        Set objToDispose = nothing
    End If

End Sub

Function SafeSQL( _
    ByVal strToCheck _
    )

    SafeSQL = Replace(strToCheck, "'", "''")

End Function
%>

Cheers
Ken


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: <ggebre@h...>
To: "Access ASP" <access_asp@p...>
Sent: Friday, June 21, 2002 2:37 PM
Subject: [access_asp] What is the solution?


: Ken replied to my posting and mentioned to me where my problem is.  I
: would appreciate if someone could help me resolve this problem.  What is
: the best way to handle this problem,  how should I rewrite the code.
:
: Your help is greatly appreciated.
: Thanks.
:
:
:
: Dim strUsers, objConn
: :
: : Set strUsers = Server.CreateObject("ADODB.Connection")
: : 'objConn.Open Server.CreateObject("ADODB.RecordSet")
: : 'rsUsers.Open Application("ADODB.ConnectionString")
: :
: :
: : If Session("CustomerID") <> " " Then
: : strUsers.Filter = "CutomerID = ' " & Session("CustomerID")
: : & " ' "
: : Else
: : strUsers.Filter = "EmailAddress = '"  & Request.Form
: : ("Email") & " '" & _
: :                 "AND Password = '" & Request.Form
: : ("Password") & " ' "
: :    If strUsers.EOF Then
: :    strUsers.AddNew
: :   End If
: :  End If


  Return to Index