javascript 从数据库字段输出多个TXT文件,该如何处理

javascript 从数据库字段输出多个TXT文件
需求描述:利用javascript 连接 ORACLE,把assp_voucher表里voucher_no,voucher_no输出到txt文件里 ,assp_voucher一条记录输出 一个 txt文件,文件名以voucher_no命名。

下面是我写的代码,只能写一个。

大虾帮我 修改下,谢谢。

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <script type="text/javascript" defer="defer">
      var strConnString = "Provider=OraOLEDB.Oracle;Data Source=evsdata;User ID=assp;Password=assp;PLSQLRset=1";
      var conn = new ActiveXObject("ADODB.Connection");
      conn.open(strConnString);
      var rs = conn.execute("select * from assp_voucher");
      document.all.voucher.value = "";
      document.all.voucher_no.value = "";
      while (!rs.EOF)
      {
//        alert(rs("voucher_no")+rs("voucher"));
       // document.all.dbContent.value = document.all.dbContent.value + rs("voucher")+"/n";
       document.all.voucher.value =rs("voucher")+"/n";
       document.all.voucher_no.value =document.all.voucher_no.value + rs("voucher_no")+"/t";
       //alert(rs("voucher_no"));
       // document.getElementById("voucher").value=rs("voucher")
        rs.moveNext;
      }
      rs.close();
      conn.close();
      conn = null;
      
//读文件   
function readFile(filename){   
    var fso = new ActiveXObject("Scripting.FileSystemObject");   
    var f = fso.OpenTextFile(filename,1);   
    var s = "";   
    while (!f.AtEndOfStream)   
        s += f.ReadLine()+"/n";   
    f.Close();   
    return s;   
}   
//  
//写文件   
function writeFile(filename,filecontent){   
    var fso, f, s ;   
    fso = new ActiveXObject("Scripting.FileSystemObject");      
    f = fso.OpenTextFile(filename,8,true);   
    f.WriteLine(filecontent);     
    f.Close();   
    alert('write ok');   

    
</script>   
    <title>无标题文档</title>
  </head>
  <body>
    <textarea id="voucher" name="voucher" rows="10" cols="100"></textarea>
    <textarea id="voucher_no" name="voucher_no" rows="5" cols="100"></textarea>
    <input type="button" value="Write!" onclick="writeFile('c:/12.txt',document.getElementById('voucher').value);"/>  
  </body>
</html>

------解决思路----------------------
引用:
Quote: 引用:


    while (!rs.EOF) {
        writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + '  ' + rs("voucher"));/////////////////////
        rs.moveNext;
    }


var rs = conn.execute("select * from assp_voucher"); 

如何把select * from assp_voucher 这句sql 通过文本框输入,然后点 一下按钮才  生成 txt文件?

你做个函数传入文本框输入的sql语句执行


<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <script type="text/javascript" defer="defer">
function executeSQL(sql){
      var strConnString = "Provider=OraOLEDB.Oracle;Data Source=evsdata;User ID=assp;Password=assp;PLSQLRset=1";
      var conn = new ActiveXObject("ADODB.Connection");
      conn.open(strConnString);
      var rs = conn.execute("select * from assp_voucher");
      document.all.voucher.value = "";
      document.all.voucher_no.value = "";
      while (!rs.EOF) {
        writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + '  ' + rs("voucher"));/////////////////////
        rs.moveNext;
    }
      rs.close();
      conn.close();
      conn = null;
    }
  
//读文件   
function readFile(filename){   
    var fso = new ActiveXObject("Scripting.FileSystemObject");   
    var f = fso.OpenTextFile(filename,1);   
    var s = "";   
    while (!f.AtEndOfStream)   
        s += f.ReadLine()+"/n";   
    f.Close();   
    return s;   
}   
//  
//写文件   
function writeFile(filename,filecontent){   
    var fso, f, s ;   
    fso = new ActiveXObject("Scripting.FileSystemObject");      
    f = fso.OpenTextFile(filename,8,true);   
    f.WriteLine(filecontent);     
    f.Close();   
    alert('write ok');   

     
</script>   
    <title>无标题文档</title>
  </head>
  <body>
    <textarea id="voucher" name="voucher" rows="10" cols="100"></textarea>
    <textarea id="voucher_no" name="voucher_no" rows="5" cols="100"></textarea>
    <input type="button" value="Write!" onclick="executeSQL(document.getElementById('voucher').value);"/>  
  </body>
</html>