Computer Learning Zone CLZ Access Excel Word Windows

With guns you can kill terrorists, with education you can kill terrorism.

-Malala Yousafzai
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
ASP

Query String

How to handle a Query String used in parameterised Query

In this tutorial you will learn how to handle parameters passed from a Query String.

       
	'CORRECT WAY - Parameterized Query with dynamic sql
	'--------------------------------------------------
	strSQL = "SELECT * FROM users WHERE username=? AND password=?"
	Dim cmd1
	Set cmd1 = Server.CreateObject("ADODB.Command")    
	cmd1.ActiveConnection = cnnLogin
	cmd1.CommandText = strSQL
	cmd1.CommandType = adCmdText
	cmd1.Parameters(0) = Request.Form("login")
	cmd1.Parameters(1) = Request.Form("password")
	Set rstLogin = cmd1.Execute()
	
 
	'BAD WAY WITH CONCATENTATION DON'T DO IT!!!
	'------------------------------------------
	strSQL = "SELECT * FROM users WHERE username='" & Request.Form("login") & _
		"' AND password='" & Request.Form("password") & "';"
	Set rstLogin = cnnLogin.Execute(strSQL)
	

What if you want a LIKE clause in your Query?

	SELECT * FROM tblX WHERE Field LIKE '%' & Name & '%'
	

Tried this but it didn't work.

	SELECT * FROM tblX WHERE Field LIKE '%?%'
	

Include ADOVBS.inc in your page to use the Constants.

	'Set parameter = command.CreateParameter (Name, Type, Direction, Size, Value)
	'cmd1.Parameters.Append(cmd1.CreateParameter("Name", 200, 1, 512, name))
	cmd1.Parameters.Append(cmd1.CreateParameter("Name", 200, 1, 512, "%" & name & "%"))
	

Or you could wrap it before you assign:

	cmd1.Parameters(0) = name
	
	cmd1.Parameters(0) = "%" & name & "%"
	

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 4:49:38 AM. PLT: 0s