title: Importing rows from CSV not importing properly
body: <p>I hope you all had a pleasant weekend!</p>
  
  <p>I am currently trying to import CSV files to a dataset.tables("CSVImportedFile"). Here is my code:</p>
  
  <pre><code>    Dim ImportCSV As New OpenFileDialog
      With ImportCSV
          .Title = "Import CSV File"
          .Filter = "PowerBI (*.csv)|*.csv"
      End With
  
      If ImportCSV.ShowDialog = DialogResult.OK Then
          Dim CSVPath As String = ImportCSV.FileName
          Dim CSVDirectory As String = Path.GetDirectoryName(CSVPath) &amp; "\"
          Dim CSVFile As String = Path.GetFileName(CSVPath)
  
          Using ImportConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" &amp; CSVDirectory &amp; ";Extended Properties=""Text;HDR=YES;""")
              Using ImportAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" &amp; CSVFile &amp; "]", ImportConnection)
                  Try
                      ImportAdapter.Fill(dset.Tables("CSVImportedFile"))
                  Catch ex As Exception
                      MessageBox.Show(ex.Message)
                  End Try
                  ImportConnection.Close()
              End Using
          End Using
  
          For Each CSVRows As DataRow In dset.Tables("CSVImportedFile").Rows
              'Trying to find the ID within the dataset column "TempID"
              Dim FindID As Integer = ourBindingSource.Find("TempID", CSVRows(0).ToString)
  
              Debug.Print FindID.ToString() &amp; " " &amp; ourBindingSource.Find("TempID", CSVRows(0).ToString)
  
              If FindID &lt; 0 Then
                  'If TemplateID does not exist
                  ourBindingSource.AddNew()
              End If
  
              'Setting all checkboxes to indeterminate
              chkBox1.CheckState = CheckState.Indeterminate
              chkBox2.CheckState = CheckState.Indeterminate
              chkBox3.CheckState = CheckState.Indeterminate
              chkBox4.CheckState = CheckState.Indeterminate
              chkBox5.CheckState = CheckState.Indeterminate
              chkBox6.CheckState = CheckState.Indeterminate
              chkBox7.CheckState = CheckState.Indeterminate
              chkBox8.CheckState = CheckState.Indeterminate
              chkBox9.CheckState = CheckState.Indeterminate
              chkBox10.CheckState = CheckState.Indeterminate
              chkBox11.CheckState = CheckState.Indeterminate
              chkBox12.CheckState = CheckState.Indeterminate
  
  
              CType(ourBindingSource.Current, DataRowView)("TempID") = CSVRows(0).ToString
              If CSVRows(3).ToString = "Section 1" Then
                  chkBox1.CheckState = CheckState.Checked
              ElseIf CSVRows(3).ToString = "Section 2" Then
                  chkBox2.CheckState = CheckState.Checked
              ElseIf CSVRows(3).ToString = "Section 3" Then
                  chkBox3.CheckState = CheckState.Checked
              ElseIf CSVRows(3).ToString = "Section 4" Then
                  chkBox4.CheckState = CheckState.Checked
              ElseIf CSVRows(3).ToString = "Section 5" Then
                  chkBox5.CheckState = CheckState.Checked
              ElseIf CSVRows(3).ToString = "Section 6" Then
                  chkBox6.CheckState = CheckState.Checked
              End If
          Next
      End If
  </code></pre>
  
  <p>Here is what my CSV looks like in a nutshell:<br></p>
  
  <pre>ID      SectionNumber
  800     Section 1
  800     Section 2
  800     Section 4
  800     Section 6
  800     Section 3
  800     Section 5
  853     Section 3
  853     Section 2
  853     Section 1
  853     Section 4
  879     Section 2
  879     Section 3
  879     Section 4
  879     Section 6
  879     Section 5</pre>
  
  <p>So what is <strong><em>supposed</em></strong> to happen is that we search for the ID. If it doesn't already exist we are adding a new row via our BindingSource and then adjusting our checkboxes as necessary. If it <strong><em>does</em></strong> exist, then we do the same thing, except we don't add a new row.</p>
  
  <p>What is actually happening though, is that not only are the checkboxes not appropriately marked off, but there are duplicate (always in twos) rows. So the rows that are added to my dataset looks like this:<br>
  800<br>
  800<br>
  853<br>
  853<br>
  879<br>
  879<br><br>
  When in reality it should look like this:<br>
  800<br>
  853<br>
  879<br><br>
  I'm so confused! Does anyone know what's going on?</p>
  
  <p><br><br>
  <strong>EDIT:</strong> 
  <br>
  Here is the following output looks like: <br></p>
  
  <pre><code>Debug.Print FindID.ToString() &amp; " " &amp; ourBindingSource.Find("TempID", CSVRows(0).ToString)
  </code></pre>
  
  <pre>-1 -1
  -1 -1
  0 0
  0 0
  0 0
  0 0
  -1 -1
  -1 -1
  2 2
  2 2
  -1 -1
  -1 -1
  4 4
  4 4
  4 4
  </pre>
  
  <p><br><br>
  <strong>EDIT 2: My ourBindingSource</strong> <br><br></p>
  
  <pre><code>Dim dataset As New DataSet
  WithEvents ourBindingSource As New BindingSource
  'Dim ourBindingSource As New BindingSource
  Dim ourDataView As New DataView
  
  ourDataView = dataset.Tables("DefaultView").DefaultView
  ourBindingSource.DataSource = ourDataView
  DGV_blk.DataSource = ourBindingSource
  
  'The sections are the SQL table headers
  chkBox1.DataBindings.Add("CheckState", ourBindingSource, "Section1", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  chkBox2.DataBindings.Add("CheckState", ourBindingSource, "Section2", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  chkBox3.DataBindings.Add("CheckState", ourBindingSource, "Section3", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  chkBox4.DataBindings.Add("CheckState", ourBindingSource, "Section4", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  chkBox5.DataBindings.Add("CheckState", ourBindingSource, "Section5", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  chkBox6.DataBindings.Add("CheckState", ourBindingSource, "Section6", True, DataSourceUpdateMode.OnValidation, CheckState.Indeterminate)
  </code></pre>
  
  <p><strong>Edit 3: My suspicions</strong><br>
  Okay so after some more tinkering I still haven't gotten anywhere with this, but I suspect that it's because when it adds a new record, it doesn't commit it. Could this have anything to do with dirty edits?</p>