title: Need help coding a loop in VB.net to create folders in windows based on usernames in remote sql db
body: <p>I already have this coded out (more or less) in Java for Linux OS, however I am not familiar enough with the syntax of .net to translate my Java code into VB2010 code... So I was hoping someone here could help me out with this.</p>
  
  <p><code>The issue:</code></p>
  
  <p>I am trying (as the title says) to create folders on my windows box based on the entries in our customer database (we have a lot, so i'm not about to do them by hand lol).</p>
  
  <p>I want to use VB.net to create a program that will loop a query through the SQL database, take the customerIDs of our clients, and create folders for each of those names in a specific directory.</p>
  
  <p><code>My Java code that I need to translate:</code></p>
  
  <pre><code>//Initializers
  Statement stmt;
  ResultSet rs;
  
  rs = stmt.executeQuery("SELECT CustomerID FROM customerlist;");
  
  System.out.println("Creating customer user database:\n");
  
  while(rs.next()){
      String str1 = rs.getString("CustomerID");
          try {
              // Create user &amp; Home Directory
                  Process p = Runtime.getRuntime().exec("sudo useradd " + str1  + " --shell /bin/sh -m " );
                  BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
  
              System.out.println("Created user: \t" + str1);
  
              String line = null;
              while ((line = in.readLine()) != null) {
                  System.out.println(line);
              }
              Thread.sleep(100);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
  }
  </code></pre>
  
  <p>I need the vb code to do the same thing, but only create the folder, and for the windows OS.</p>
  
  <p><code>Important notes:</code></p>
  
  <ul>
  <li>I am using <code>Imports MySql.Data.MySqlClient</code> to make the db connection.</li>
  <li>it is a REMOTE mysql server, not a local one (don't know if this note was needed).</li>
  <li>We have close to 6,000 clients... (thus why i'm NOT doing it by hand!)</li>
  <li>The boss says to switch from Java to VB, so no arguing the point of sticking to Java please..</li>
  </ul>
  
  <hr>
  
  <p>Seeing as how people are thinking that i'm asking for a handout for the entire program... here is what I have so far:</p>
  
  <pre><code>Private Sub ButtonLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLogin.Click
      conn = New MySqlConnection()
      conn.ConnectionString = "server=xxx" &amp; ";" &amp; "user id=xxx" &amp; ";" &amp; "password=xxx" &amp; ";" &amp; "database=companysqldb"
      Try
          conn.Open()
          MessageBox.Show("Connection Opened Successfully")
  
          'while loop pseudo
          '------------------
          'set query string to "SELECT CustomerID FROM customerlist;"
          'while looping through query
              'set stringvar to current loop's CustomerID
  
              'Create directory
              If(Not System.IO.Directory.Exists("c:\pub\users\" &amp; stringvar)) Then System.IO.Directory.CreateDirectory("c:\pub\users\" &amp; stringvar)
              RichTextBox.AppendText(vbCrLf &amp; "Added folder: " &amp; stringvar)
              RichTextBox.ScrollToCaret()
  
          'end while loop
  
      Catch myerror As MySqlException
          MessageBox.Show("Error Connecting to Database: " &amp; myerror.Message)
      End Try
  
  End Sub
  </code></pre>
  
  <p>As you can see, I have most of it already written out, however my primary difficulty is the syntax of the while loop and the SQL Query.</p>