Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Please Help - Access Parameter Queries


Message #1 by Martin Lee <access@o...> on Tue, 23 Apr 2002 21:12:50 +0800
Good Evening All:

would appreciate any help or opinions anyone can provide.

Have been trying to locate information on using Access Parameter Queries 
with ASP and while there is a wealth of information on SQL Stored 
procedures, have only come across:

http://www.4guysfromrolla.com/webtech/021799-1.shtml

It seems that, while SQL Stored Procedures can execute multiple SQL 
statements within a Stored Procedure and use Return Values, this does not 
seem possible with Access Parameter Queries.

The only way we can figure out returning a value from a Parameter Query, is 
to use the value returned by the number of records affected by the query. eg:

Say letting users change their passwords and use the following update query:

PARAMETERS [@Password] Text ( 255 ), [@UserName] Text ( 255 );
UPDATE tblUsers SET tblUsers.Password = [@Password]
WHERE (((tblUsers.Password)<>[@Password]) AND 
((tblUsers.UserName)=[@UserName]));


and execute as:

With cmdUpdate
		
	.ActiveConnection = objconn
	.CommandText = "qupdPass"
	.CommandType = adCmdStoredProc
	
	.Parameters.Append = cmdUpdate.CreateParameter("@Password", adVarWChar, 
adParamInput, 50, strPassword)
	.Parameters.Append = cmdUpdate.CreateParameter("@UserName", adVarWChar, 
adParamInput, 50, strUserName)
	.Execute lngRecs, , adExecuteNoRecords
			
End With

If lngRecs = 0 we know that the record was not updated since new and old 
password are the same (or some other error?) and then can display the 
appropriate message.

Now, what if we needed to update and validate two fields, instead of just 
the password field. The query would only return 1 or 0 and we would have no 
way of knowing which of the two fields caused the query not to update the 
record.

Any ideas on how to achieve this?

Due to the limitations of Parameter Queries, is there any advantages to 
using them instead of coding the SQL statements?

Thanks for any ideas, help or opinions.

Martin






  Return to Index