locked
problems with creating my own object RRS feed

  • Question

  • Hi.

    I would like to create my own object but I have strange problem. Take a look at this example:

     

    var ObjProperites = new GetProperties(DBConnection);  
    AddHTML("Properites: " + ObjProperites.RecID + " " + ObjProperites.Title); //this wont return any properties   
     
    function GetProperties(Connection) {  
      try {  
        var rsRaporty = new ActiveXObject("ADODB.Recordset");  
        rsRaporty.ActiveConnection = Connection;  
        rsRaporty.Source = "SELECT TOP 1 * FROM dbo.MyTable";  
        rsRaporty.Open();  
        this.RecID = rsRaporty("RecID");  
        this.Title = rsRaporty("Title");  
      }   
      catch(E) {  
        AddHTML("Failed: " + E.Message + "<BR>");  
        return null;      
      }   
      finally { //why freeing or even closing recordset makes this.RecID, this.Title empty ?  
       if (rsRaporty.State == adStateOpen)  
         rsRaporty.Close;  
       rsRaporty = null;  
      }  

     

    I would like to have a constructor which takes my existing DBConnection, opens a recordset and assigns some of its values to my newly created object.  This works ONLY if I do not close the recordset. How is that? How to make it work right?

    Thanks for your time.

    After edition:

    Ok, I know where lies the problem rsRaporty("RecID");  returns me a reference to an object not the actual value of the column.

    • Edited by Heavenwood Wednesday, January 28, 2009 2:12 PM found solution on my own
    Wednesday, January 28, 2009 12:46 PM