title: Visual Studio 2012 OLEDB connection
body: <p>I have this code that I am using in visual studio 2012 to populate a combobox from data in a sql database.  Every time I try to debug it I get the exception at the for loop of a null reference exception.  I am hoping someone can help me figure out what it is I am missing here.  </p>
  
  <p>Private Sub StationList_Click(sender As Object, e As EventArgs) Handles StationList.Click</p>
  
  <pre><code>    Dim cn As New OleDbConnection
      cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\hendera2\Desktop\StationEquip.accdb"
      Dim Mystr As String = "SELECT DISTINCT Location FROM StationEquipment"
      Dim Myadapter As OleDbDataAdapter
      Dim Mydataset As New DataSet()
  
  
  
      Try
          cn.Open()
  
          Myadapter = New OleDbDataAdapter(Mystr, cn.ConnectionString)
          Myadapter.Fill(Mydataset, Mystr)
  
  
  
  
          Dim dr As DataRow
  
          For Each dr In Mydataset.Tables("StationEquipDataSet").Rows
              Me.StationList.Items.Add(dr("Location"))
          Next
  
          cn.Close()
      Catch ex As Exception
          MsgBox("Cannot Open connection")
      End Try
  End Sub
  </code></pre>