Results 1 to 3 of 3

Thread: Writting an ADO Recordset Into Array ~ How do I do it?

  1. #1
    Join Date
    Oct 2011
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Writting an ADO Recordset Into Array ~ How do I do it?

    Hello,

    I really need your help.

    How can I use the following recordset model below to build an array containing a row of cell data?

    Code:
    while (!rs.eof) {
    
        for (var c = 0; c < rs.fields.count; ++c) {
    
            alert(i +" " +rs.fields(c).value)
    
        }
        rs.MoveNext
    }
    The objective of the code would be to achieve something exactly similar to the given example below:
    Code:
    var data = [ [1,'Exxon Mobil','339,938.0','36,130.0'],
            [2,'Wal-Mart Stores','315,654.0','11,231.0'],
            [3,'Royal Dutch Shell','306,731.0','25,311.0'],
            [4,'BP','267,600.0','22,341.0'],
            [5,'General Motors','192,604.0','-10,567.0'],
            [6,'Chevron','189,481.0','14,099.0'],
            [7,'DaimlerChrysler','186,106.3','3,536.3'],
            [8,'Toyota Motor','185,805.0','12,119.6'],
            [9,'Ford Motor','177,210.0','2,024.0'],
            [10,'ConocoPhillips','166,683.0','13,529.0'],
            [11,'General Electric','157,153.0','16,353.0'],         
            [12,'Total','152,360.7','15,250.0'],                
            [13,'ING Group','138,235.3','8,958.9'],
            [14,'Citigroup','131,045.0','24,589.0'],
            [15,'AXA','129,839.2','5,186.5'],
            [16,'Allianz','121,406.0','5,442.4'],
            [17,'Volkswagen','118,376.6','1,391.7'],
            [18,'Fortis','112,351.4','4,896.3'],
            [19,'Crédit Agricole','110,764.6','7,434.3'],
            [20,'American Intl. Group','108,905.0','10,477.0']];
    I've tried the following, but it isn't working like intended:
    Code:
    	if (!rs.BOF || !rs.EOF) {
    	
    		var i = 0
    		alert(rs.fields.count) // max row number
    		data = [
    		while (!rs.eof) {
    		++i
    
    			for (var c = 0; c < rs.fields.count; ++c) {
    	
    				alert(i +" " +rs.fields(c).value)
    				 data += [i,rs.fields(c).value,rs.fields(c).value,rs.fields(c).value]
    			}
    			rs.MoveNext
    			
    		}
    		data += ]
    		alert(data)			
    	}//end of if

  2. #2
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    //The best way is to use array's push method

    var data = [];

    if (!rs.BOF || !rs.EOF) {

    var i = 0
    alert(rs.fields.count) // max row number

    while (!rs.eof) {
    ++i

    for (var c = 0; c < rs.fields.count; ++c) {

    alert(i +" " +rs.fields(c).value);
    data.push([i,rs.fields(c).value,rs.fields(c).value,rs.fields(c).value]);
    }
    rs.MoveNext

    }

    alert(data)
    }//end of if


    //Hope this will help

  3. #3
    Join Date
    Oct 2011
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Another flawless post brought to you by zealous!

    That was exactly what I was looking for.

    Thanks so much for all your help.

    Cheers,

    Jay

Similar Threads

  1. ASP parser and recordset
    By radujit in forum ASP
    Replies: 1
    Last Post: 02-05-2011, 05:55 PM
  2. Filter recordset
    By dmrgraphics.com in forum PHP
    Replies: 13
    Last Post: 09-17-2009, 07:56 PM
  3. writting files
    By bluewalrus in forum PHP
    Replies: 11
    Last Post: 10-26-2008, 02:28 PM
  4. Recordset - Javascript
    By vbjohn in forum JavaScript
    Replies: 0
    Last Post: 01-30-2007, 08:39 PM
  5. Importing Recordset to asp form
    By apostolos in forum ASP
    Replies: 0
    Last Post: 11-15-2005, 06:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •