title: How do I assign the results of an SQL query to multiple variables in VB.NET?
body: <p>This is my first attempt at writing a program that accesses a database from scratch, rather than simply modifying my company's existing programs. It's also my first time using VB.Net 2010, as our other programs are written in VB6 and VB.NET 2003. We're using SQL Server 2000 but should be upgrading to 2008 soon, if that's relevant.</p>
  
  <p>I can successfully connect to the database and pull data via query and assign, for instance, the results to a combobox, such as here:</p>
  
  <pre><code>Private Sub PopulateCustomers()
      Dim conn As New SqlConnection()
      Dim SQLQuery As New SqlCommand
      Dim daCustomers As New SqlDataAdapter
      Dim dsCustomers As New DataSet
  
      conn = GetConnect()
      Try
          SQLQuery = conn.CreateCommand
          SQLQuery.CommandText = "SELECT Customer_Name, Customer_ID FROM Customer_Information ORDER BY Customer_Name"
          daCustomers.SelectCommand = SQLQuery
          daCustomers.Fill(dsCustomers, "Customer_Information")
  
          With cboCustomer
              .DataSource = dsCustomers.Tables("Customer_Information")
              .DisplayMember = "Customer_Name"
              .ValueMember = "Customer_ID"
              .SelectedIndex = -1
          End With
  
      Catch ex As Exception
          MsgBox("Error: " &amp; ex.Source &amp; ": " &amp; ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
      End Try
  
      conn.Close()
  
  End Sub
  </code></pre>
  
  <p>I also have no problem executing a query that pulls a single field and assigns it to a variable using ExecuteScalar. What I haven't managed to figure out how to do (and can't seem to hit upon the right combination of search terms to find it elsewhere) is how to execute a query that will return a single row and then set various fields within that row to individual variables.</p>
  
  <p>In case it's relevant, here is the GetConnect function referenced in the above code:</p>
  
  <pre><code>Public Function GetConnect()
       conn = New SqlConnection("Data Source=&lt;SERVERNAME&gt;;Initial Catalog=&lt;DBNAME&gt;;User Id=" &amp; Username &amp; ";Password=" &amp; Password &amp; ";")
       Return conn
  End Function
  </code></pre>
  
  <p>How do I execute a query so as to assign each field of the returned row to individual variables?</p>