title: How to copy from a database to a text file using VBScript?
body: <p>I have an example in C# code, but it is using <code>streamWriter</code>. It must be involving with <code>FileSystemObject</code> rite. If yes, what are methods should I use?  I want to code using VBScript <a href="http://en.wikipedia.org/wiki/Windows_Script_Host" rel="nofollow noreferrer">WSH</a>, and my database is MS <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server#SQL_Server_2005" rel="nofollow noreferrer">SQL Server 2005</a>.</p>
  
  <p>Any solution, references, or guide are helpful.</p>
  
  <pre><code>using (StreamWriter tw = File.AppendText("c:\\INMS.txt"))
  {
      using (SqlDataReader reader = cmd.ExecuteReader())
      {
          tw.WriteLine("id, ip address, message, datetime");
          while (reader.Read())
          {
              tw.Write(reader["id"].ToString());
              tw.Write(", " + reader["ip"].ToString());
              tw.Write(", " + reader["msg"].ToString());
              tw.WriteLine(", " + reader["date"].ToString());
          }
          tw.WriteLine("Report Generate at : " + DateTime.Now);
          tw.WriteLine("---------------------------------");
          tw.Close();
          reader.Close();
      }
  }
  </code></pre>