Forum Discussion

raghu_kamalapur's avatar
raghu_kamalapur
Frequent Visitor
10 years ago
Solved

I need help in executing query and that should stored in recordset variable.

I am using ADO commands for executing query and I tried to execute simple query and assign recordset as avariable. while debugging I am not able to see any data.

 

Below is function written 

 

// this function returnsa record set for specified table name
function GetRecordSet( db_table_name )
{
var projectName = "xyz";
var aCon1, aCmd, aRecSet;
aCon1 = ADO["CreateConnection"]();
aCon1["ConnectionString"] = "Provider="SQLNCLI11;Server=localhost;" +"Database=" + projectName + "Data;Integrated Security=SSPI;";
aCon1["Open"]();
aCmd = ADO["CreateCommand"](); // Creates a command and specifies its parameters
aCmd["ActiveConnection"] = aCon1; // Connection
aCmd["CommandType"] = adCmdTable; // Command type
aCmd["CommandText"] = db_table_name; // Table name
aRecSet = aCmd["Execute"]();
aRecSet["MoveFirst"]();
return aRecSet;
}

 

after aRecSet = aCmd["Execute"](); tried to debug I am not able to see data even though I have data in specified table. Connection is happening

 

Please help

  • Try removing this line:

    aRecSet["MoveFirst"]();

     Seems like the recordset should already be at the first row.

     

    Also your command text seems to just be a table name? Are you passing the entire statement as db_table_name?

    Perhaps you mean to pull everything from the table specified like so?:

     

    aCmd["CommandText"] = "Select * from " + db_table_name; // Table name

     

    Resulting in:

    function GetRecordSet( db_table_name ) 
    {
    var projectName = "xyz";
    var aCon1, aCmd, aRecSet;
    aCon1 = ADO["CreateConnection"]();
    aCon1["ConnectionString"] = "Provider="SQLNCLI11;Server=localhost;" +"Database=" + projectName + "Data;Integrated Security=SSPI;"; 
    aCon1["Open"](); 
    aCmd = ADO["CreateCommand"](); // Creates a command and specifies its parameters
    aCmd["ActiveConnection"] = aCon1; // Connection
    aCmd["CommandType"] = adCmdTable; // Command type
    aCmd["CommandText"] = "Select * From " + db_table_name; // Table name
    aRecSet = aCmd["Execute"]();
    return aRecSet; 
    }

     

1 Reply

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    Try removing this line:

    aRecSet["MoveFirst"]();

     Seems like the recordset should already be at the first row.

     

    Also your command text seems to just be a table name? Are you passing the entire statement as db_table_name?

    Perhaps you mean to pull everything from the table specified like so?:

     

    aCmd["CommandText"] = "Select * from " + db_table_name; // Table name

     

    Resulting in:

    function GetRecordSet( db_table_name ) 
    {
    var projectName = "xyz";
    var aCon1, aCmd, aRecSet;
    aCon1 = ADO["CreateConnection"]();
    aCon1["ConnectionString"] = "Provider="SQLNCLI11;Server=localhost;" +"Database=" + projectName + "Data;Integrated Security=SSPI;"; 
    aCon1["Open"](); 
    aCmd = ADO["CreateCommand"](); // Creates a command and specifies its parameters
    aCmd["ActiveConnection"] = aCon1; // Connection
    aCmd["CommandType"] = adCmdTable; // Command type
    aCmd["CommandText"] = "Select * From " + db_table_name; // Table name
    aRecSet = aCmd["Execute"]();
    return aRecSet; 
    }