This topic is locked
[SOLVED]

 Access Database Through ASP Code Snippet

5/12/2011 6:55:50 AM
ASPRunnerPro General questions
M
MrDerp author

I would like to use a custom ASP code snippet to query a database and return a result. I have added a custom event in the Edit screen and then, in the Events screen, I have added the following action:



'********** Check if specific record exists ************

dim rsExists

set rsExists = dal.table.Query("column='value'","")

if not rsExists.eof then

' if record exists do something
else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing


However, this returns the following error:



Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'dal.table'


Any idea how I can fix this? Are there any alternative means of querying a database within a custom ASP snippet?

Admin 5/12/2011

You need to use the real table name instead of table.
If you cannot manage using DAL use any ASP code snippet there. Here is an example of retrieving data in plain ASP:

http://www.webdesign.org/web-programming/asp/reading-a-database.4283.html

M
MrDerp author 5/13/2011

I am using the real table name - I just wanted to give you an example of the code I'm using.
I'm okay with generating my own custom SQL query but I need to reference one of the fields from the currently selected record.



Dim tmpDict, desc, id
sql = "select apdsc_name as user from apdesc where apdsc_type = 'R' and apdsc_code = '" & values("xxsrq_user1") & "'"

Set rstmp = server.CreateObject("ADODB.Recordset")

rstmp.open sql,dbConnection
Response.Write rstmp("user")


How would I refer to a field currently on screen in an ASP code snippet? Using values/dict doesn't work so I'm not sure how I would retrieve this data?
Thanks.

Admin 5/14/2011

In ASP code snippet you don't have direct access to field values.
I recommend you to check this article:

http://xlinesoft.com/blog/2011/04/28/taming-the-beast-events-buttons-and-code-snippets/
See Insert PHP/ASP code snippet->Session variables session.
PS. in regards to my "real table name" comment.

dal.table.Query is incorrect while dal.apdesc.Query is correct.