We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More

Forum Discussion

Krishna_Kumar's avatar
Krishna_Kumar
Contributor
6 years ago
Solved

Read csv using Javascript

Hi everyone,

 

can any one guide me how to read a csv file using ado connection using javascrip.

 

Regards,

Krishna Kumar

  • tristaanogre's avatar
    tristaanogre
    6 years ago

    I wouldn't ready the file via an SQL query.  I've done this in the past.  Use aqFile.OpenTextFile (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/opentextfile.html) to open the file for reading.  Then simply use the ReadLine method to read each line of the file in as you loop through the record set from your DB query.  You can then use, for the line itself, the aqString.GetListItem(https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/getlistitem.html) and other supporting methods to get the particular fields out of the line of the CSV file.

    Alternatively... you could still use DDT.CSVDriver to open the CSV file and then, within a loop based upon the resulting DDT object, compare fields and rows as you loop through.  

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Why do you need to use an ADO connection?  What are you intending to do?  If you're looking at doing a data driven script, simply use the DDT.CSVDriver object.


    • Krishna_Kumar's avatar
      Krishna_Kumar
      Contributor

      Requirement is to compare the CSV file with the DB values.

      So though of using same query to retrieve the data.

       

      Regards,

      Krishna

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I wouldn't ready the file via an SQL query.  I've done this in the past.  Use aqFile.OpenTextFile (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/opentextfile.html) to open the file for reading.  Then simply use the ReadLine method to read each line of the file in as you loop through the record set from your DB query.  You can then use, for the line itself, the aqString.GetListItem(https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/getlistitem.html) and other supporting methods to get the particular fields out of the line of the CSV file.

        Alternatively... you could still use DDT.CSVDriver to open the CSV file and then, within a loop based upon the resulting DDT object, compare fields and rows as you loop through.