Simple database query using asp and ms access
am 18.04.2006 09:17:46 von Malcolm
Hi again folks, I want to make a simple database query using asp and ms
access.
I want to be able to query the database and return either available or not!!
ie JohnSmith is available
or JohnSmith is not availble
if the name is available it is because it does not exist in the database
and if it is not available .. This is because another user already has that
username.
Any ideas on a simple script for this :-)
Regards
Malcolm
Re: Simple database query using asp and ms access
am 18.04.2006 15:26:49 von reb01501
malcolm wrote:
> Hi again folks, I want to make a simple database query using asp and
> ms access.
>
>
>
> I want to be able to query the database and return either available
> or not!!
>
>
>
> ie JohnSmith is available
>
> or JohnSmith is not availble
>
>
>
> if the name is available it is because it does not exist in the
> database
>
> and if it is not available .. This is because another user already
> has that username.
>
>
>
> Any ideas on a simple script for this :-)
>
>
Simple is an understatement!
Why do you ask a database-related question without providing:
the name of the database
the names of the relevant tables in the database
the names and datatypes of the relevant fields in the database
Given a database file called db.mdb, a table called CurrentUsers and a Text
field called CurrUserName:
dim newname,sql, arParms, cn, cmd, rs
'substitute the real source of the name:
newname=request.form("newname")
'validate the newname - make sure it doesn't contain
'anything malicious or unwanted (like INSERT or SELECT)
'if it's valid, then continue:
arParms=array(newname)
sql="select count(*) from CurrentUsers where CurrUserName=?"
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=" & server.mappath("db.mdb")
set cmd=createobject("adodb.command")
with cmd
.commandtext=sql
.commandtype=1 'adCmdText
set .activeconnection=cn
set rs=cmd.execute(,arParms)
end with
if rs(0) > 0 then
'user name exists
else
'user name does not exist
end if
rs.close: set rs=nothing
set cmd=nothing
cn.close: set cn=nothing
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.