|
 |
asp_web_howto thread: Finding Database Value
Message #1 by "Jonathan Marshall" <jdmarsh2g@h...> on Wed, 15 May 2002 02:05:10 +0000
|
|
<html><div style='background-color:'><DIV>What is the best way to check and see if a
certain value is present in a database. If I want to check for a Id number being present in a field how can manipulate that
collection of ID's and check for a number. <BR>jdm</DIV></div><br clear=all><hr>Send and receive
Hotmail on your mobile device: <a href='http://g.msn.com/1HM305401/45'>Click Here</a><br></html>
Message #2 by "Ken Schaefer" <ken@a...> on Wed, 15 May 2002 12:39:08 +1000
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Jonathan Marshall" <jdmarsh2g@h...>
Subject: [asp_web_howto] Finding Database Value
: What is the best way to check and see if a certain value is
: present in a database. If I want to check for a Id number being
: present in a field how can manipulate that collection of ID's
: and check for a number.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Depends on where you want to implement this business logic. In ASP it would
be something like:
<%
strVar = "this-is-a-test-ID"
strSQL = _
"SELECT field1 " & _
"FROM table1 " & _
"WHERE IDField = '" & strVar & "'"
objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If objRS.EOF then
' Value is not present
Else
' Value is present
End If
%>
Alternatively, you could put it into your database:
CREATE PROC usp_mySproc
@UserID int
AS
IF EXISTS
(
SELECT NULL
FROM Users
WHERE UserID = @UserID
)
--UserID Exists
BEGIN
-- return an error code
RETURN 1
END
ELSE
BEGIN
-- do something else
END
Cheers
Ken
Message #3 by "Jonathan Marshall" <jdmarsh2g@h...> on Wed, 15 May 2002 05:15:38 +0000
|
|
<html><div style='background-color:'><DIV>
<P>thanks Ken<BR></P></DIV>
<DIV></DIV>
<DIV></DIV>>From: "Ken Schaefer" <KEN@A...>
<DIV></DIV>>Reply-To: "ASP Web HowTo" <ASP_WEB_HOWTO@P...>
<DIV></DIV>>To: "ASP Web HowTo" <ASP_WEB_HOWTO@P...>
<DIV></DIV>>Subject: [asp_web_howto] Re: Finding Database Value
<DIV></DIV>>Date: Wed, 15 May 2002 12:39:08 +1000
<DIV></DIV>>
<DIV></DIV>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DIV></DIV>>From: "Jonathan Marshall" <JDMARSH2G@H...>
<DIV></DIV>>Subject: [asp_web_howto] Finding Database Value
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>: What is the best way to check and see if a certain value is
<DIV></DIV>>: present in a database. If I want to check for a Id number being
<DIV></DIV>>: present in a field how can manipulate that collection of ID's
<DIV></DIV>>: and check for a number.
<DIV></DIV>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DIV></DIV>>
<DIV></DIV>>Depends on where you want to implement this business logic. In ASP it would
<DIV></DIV>>be something like:
<DIV></DIV>>
<DIV></DIV>><%
</DIV>>strVar = "this-is-a-test-ID"
</DIV>>
</DIV>>strSQL = _
</DIV>> "SELECT field1 " & _
</DIV>> "FROM table1 " & _
</DIV>> "WHERE IDField = '" & strVar & "'"
</DIV>>
</DIV>>objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
</DIV>>
</DIV>>If objRS.EOF then
</DIV>> ' Value is not present
</DIV>>Else
</DIV>> ' Value is present
</DIV>>End If
</DIV>>%>
<DIV></DIV>>
<DIV></DIV>>Alternatively, you could put it into your database:
<DIV></DIV>>
<DIV></DIV>>CREATE PROC usp_mySproc
<DIV></DIV>>
<DIV></DIV>> @UserID int
<DIV></DIV>>
<DIV></DIV>>AS
<DIV></DIV>>
<DIV></DIV>> IF EXISTS
<DIV></DIV>> (
<DIV></DIV>> SELECT NULL
<DIV></DIV>> FROM Users
<DIV></DIV>> WHERE UserID = @UserID
<DIV></DIV>> )
<DIV></DIV>> --UserID Exists
<DIV></DIV>> BEGIN
<DIV></DIV>> -- return an error code
<DIV></DIV>> RETURN 1
<DIV></DIV>> END
<DIV></DIV>> ELSE
<DIV></DIV>> BEGIN
<DIV></DIV>> -- do something else
<DIV></DIV>> END
<DIV></DIV>>
<DIV></DIV>>Cheers
<DIV></DIV>>Ken
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>---
<DIV></DIV>>
<DIV></DIV>>Improve your web design skills with these new books from Glasshaus.
<DIV></DIV>>
<DIV></DIV>>Usable Web Menus
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>Constructing Accessible Web Sites
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>Practical JavaScript for the Usable Web
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>---
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV></div><br clear=all><hr>MSN Photos is the easiest way to share and print your photos: <a
href='http://g.msn.com/1HM305401/46'>Click Here</a><br></html>
Message #4 by "Drew, Ron" <RDrew@B...> on Wed, 15 May 2002 07:46:32 -0400
|
|
This is a multi-part message in MIME format.
------_=_NextPart_001_01C1FC06.288200B3
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Depends on what you are trying to look for.
SELECT blah FROM tablename
WHERE
theID =3D 123 ...or... < or >
theID IN (123,124,125) ....or....if looking for an alpha the above
plus
theID LIKE 'alpha%' ...or... theID LIKE '%alpha' ...or...theID LIKE
'%alpha%'
Dont forget the check for EOF BOF
-----Original Message-----
From: Jonathan Marshall [mailto:jdmarsh2g@h...]
Sent: Tuesday, May 14, 2002 10:05 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Finding Database Value
What is the best way to check and see if a certain value is present in a
database. If I want to check for a Id number being present in a field
how can manipulate that collection of ID's and check for a number.
jdm
_____
Send and receive Hotmail on your mobile device: Click Here
<http://g.msn.com/1HM305401/45>
--- Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20 Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20 Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20 ---
Message #5 by "Jonathan Marshall" <jdmarsh2g@h...> on Wed, 15 May 2002 20:01:05 +0000
|
|
<html><div style='background-color:'><DIV>Okay ken but when I try that I stilll get an
error saying that an exception occurred I will try some other things and see what happens thanks</DIV>
<DIV></DIV>
<DIV></DIV>>From: "Ken Schaefer" <KEN@A...>
<DIV></DIV>>Reply-To: "ASP Web HowTo" <ASP_WEB_HOWTO@P...>
<DIV></DIV>>To: "ASP Web HowTo" <ASP_WEB_HOWTO@P...>
<DIV></DIV>>Subject: [asp_web_howto] Re: Finding Database Value
<DIV></DIV>>Date: Wed, 15 May 2002 12:39:08 +1000
<DIV></DIV>>
<DIV></DIV>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DIV></DIV>>From: "Jonathan Marshall" <JDMARSH2G@H...>
<DIV></DIV>>Subject: [asp_web_howto] Finding Database Value
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>: What is the best way to check and see if a certain value is
<DIV></DIV>>: present in a database. If I want to check for a Id number being
<DIV></DIV>>: present in a field how can manipulate that collection of ID's
<DIV></DIV>>: and check for a number.
<DIV></DIV>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<DIV></DIV>>
<DIV></DIV>>Depends on where you want to implement this business logic. In ASP it would
<DIV></DIV>>be something like:
<DIV></DIV>>
<DIV></DIV>><%
</DIV>>strVar = "this-is-a-test-ID"
</DIV>>
</DIV>>strSQL = _
</DIV>> "SELECT field1 " & _
</DIV>> "FROM table1 " & _
</DIV>> "WHERE IDField = '" & strVar & "'"
</DIV>>
</DIV>>objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
</DIV>>
</DIV>>If objRS.EOF then
</DIV>> ' Value is not present
</DIV>>Else
</DIV>> ' Value is present
</DIV>>End If
</DIV>>%>
<DIV></DIV>>
<DIV></DIV>>Alternatively, you could put it into your database:
<DIV></DIV>>
<DIV></DIV>>CREATE PROC usp_mySproc
<DIV></DIV>>
<DIV></DIV>> @UserID int
<DIV></DIV>>
<DIV></DIV>>AS
<DIV></DIV>>
<DIV></DIV>> IF EXISTS
<DIV></DIV>> (
<DIV></DIV>> SELECT NULL
<DIV></DIV>> FROM Users
<DIV></DIV>> WHERE UserID = @UserID
<DIV></DIV>> )
<DIV></DIV>> --UserID Exists
<DIV></DIV>> BEGIN
<DIV></DIV>> -- return an error code
<DIV></DIV>> RETURN 1
<DIV></DIV>> END
<DIV></DIV>> ELSE
<DIV></DIV>> BEGIN
<DIV></DIV>> -- do something else
<DIV></DIV>> END
<DIV></DIV>>
<DIV></DIV>>Cheers
<DIV></DIV>>Ken
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>---
<DIV></DIV>>
<DIV></DIV>>Improve your web design skills with these new books from Glasshaus.
<DIV></DIV>>
<DIV></DIV>>Usable Web Menus
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>Constructing Accessible Web Sites
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>Practical JavaScript for the Usable Web
<DIV></DIV>>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
<DIV></DIV>>r-20
<DIV></DIV>>---
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV></div><br clear=all><hr>MSN Photos is the easiest way to share and print your photos: <a
href='http://g.msn.com/1HM305401/46'>Click Here</a><br></html>
|
|
 |