Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am writing code on a page to upload files.I wanted to test this code but I am getting database error in the functions which already existed before. I have checked the code for missing variables if any but everything seems to be fine. Due to this I am not able to test the code I wrote.I get the following error:

An Error Was Encountered!. Description: Variable is undefined. Number: 500. Source: Microsoft VBScript runtime error.
Database error encountered in DBGetCoursesJS(). Please contact your SharedHR Administrator.

Following is the code for the method:
VB
function DBGetCoursesJS()
	Dim objRS, sSQL
	Dim strSelected

	DBGetCoursesJS = false
	sSQL = "SELECT CourseID, CourseName, DefaultVendor, DefaultTrainer, DefaultLocation, DefaultHours, DefaultLifeSpan"
	sSQL = sSQL &  " FROM TrainingCourses"
	sSQL = sSQL & " WHERE CompID = " & intCompID
	sSQL = sSQL &   " AND ProgramID = " & intProgramID
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open sSQL, objConnect, adOpenStatic, adLockReadOnly, adCmdText
	if DBCheckError() then
		strClientMessage = strClientMessage & "Database error encountered in DBGetCoursesJS().  Please contact your " & strAppTitle & " Administrator." & vbCRLF
		DbGetCoursesJS = false
		exit function
end if

	Dim iCnt, strArrayItem
	iCnt = 0
	while not objRS.EOF
		strArrayItem = ""
		strArrayItem = "arrCourses[" & iCnt & "] = new Course("""
		strArrayItem = strArrayItem & objRS("CourseID") & """, """
		strArrayItem = strArrayItem & objRS("CourseName") & """, """
		strArrayItem = strArrayItem & objRS("DefaultVendor") & """, """
		strArrayItem = strArrayItem & objRS("DefaultTrainer") & """, """
		strArrayItem = strArrayItem & objRS("DefaultLocation") & """, """
		strArrayItem = strArrayItem & objRS("DefaultHours") & """, """
		strArrayItem = strArrayItem & objRS("DefaultLifeSpan") & """);"
		Response.Write(strArrayItem & vbNewLine)
		iCnt = iCnt + 1
		objRS.MoveNext
	wend
	objRS.Close
	Set objRS = Nothing
	DbGetCoursesJS = true
end function
Posted
Updated 24-Nov-14 7:04am
v4
Comments
purva0215 24-Nov-14 12:42pm    
Sorry, actually by mistake I had copied just half the code. I have now updated the function to contain entire code.

Irrespective of your question, Do you know that this implementation is susceptible of SQL Injection[^]?

I would suggest you to rather use Stored Procedure[^] or Parameterized Queries[^] in SQL.
 
Share this answer
 
Shouldn't your last line be end function?
Also, try using the number equivalents of the ado constants, and leave off the adCmdText.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900