smccafferty
12 years agoOccasional Contributor
Trying to Assign an SQL returned value to a Project Variable
Hey there.
I've been trying for a while to assign a value (returned from a SQL query) to a local variable.
Here's the code:
function SetCourseID()
{
var aCon, aCmd, setCourseID;
var localCourseID;
// Creates ADO connection
aCon = ADO["CreateConnection"]();
// Sets up the connection parameters
aCon["ConnectionString"] = "Provider=SQLOLEDB.1;Password=****************;Persist Security Info=True;User ID=***********;Initial Catalog=**************************;Data Source=********************************";
// Opens the connection
aCon["Open"]();
//Set Course ID for test 2350: Initialize Command
setCourseID = ADO["CreateCommand"]();
setCourseID["ActiveConnection"] = aCon;
setCourseID["CommandType"] = adCmdText;
// Execute SQL Command to find and remove previous t2350 courses
setCourseID["CommandText"] = "select CourseID from course where name = 't2350 - Single Video - One Section - No Survey'";
localCourseID = setCourseID["Execute"]();
Project.Variables.AddVariable("t2350_CourseID","String");
Project.Variables.t2350_CourseID = localCourseID;
aCon["Close"]();
}
I know the query returns an integer and I know the connection string is spot on (I use it in other scripts to delete and add items).
The problem is a mismatch on this line:
Project.Variables.t2350_CourseID = localCourseID;
This is probably something very silly as I've been looking at this for ages!
Please help!
I've been trying for a while to assign a value (returned from a SQL query) to a local variable.
Here's the code:
function SetCourseID()
{
var aCon, aCmd, setCourseID;
var localCourseID;
// Creates ADO connection
aCon = ADO["CreateConnection"]();
// Sets up the connection parameters
aCon["ConnectionString"] = "Provider=SQLOLEDB.1;Password=****************;Persist Security Info=True;User ID=***********;Initial Catalog=**************************;Data Source=********************************";
// Opens the connection
aCon["Open"]();
//Set Course ID for test 2350: Initialize Command
setCourseID = ADO["CreateCommand"]();
setCourseID["ActiveConnection"] = aCon;
setCourseID["CommandType"] = adCmdText;
// Execute SQL Command to find and remove previous t2350 courses
setCourseID["CommandText"] = "select CourseID from course where name = 't2350 - Single Video - One Section - No Survey'";
localCourseID = setCourseID["Execute"]();
Project.Variables.AddVariable("t2350_CourseID","String");
Project.Variables.t2350_CourseID = localCourseID;
aCon["Close"]();
}
I know the query returns an integer and I know the connection string is spot on (I use it in other scripts to delete and add items).
The problem is a mismatch on this line:
Project.Variables.t2350_CourseID = localCourseID;
This is probably something very silly as I've been looking at this for ages!
Please help!