title: How to delete row from both Datagridview and the record from the table
body: <p>In my datagridview, you can select a row, and upon pressing a button, the content of two of the four fields is transported to another table. At this point, the row selected in my datagridview should be deleted from both the datagridview and the table it's reading from. Currently I am able to take the two fields I need and put them into the other table, but am having difficulty deleting this record after. </p>
  
  <p>This is my code:  </p>
  
  <pre><code>Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\..\RailwayDatabase2.accdb"  
          Dim Con As OleDb.OleDbConnection  
          Dim comm As OleDbCommand  
          Dim rowval As Integer  
          Dim connect, query As String  
          Try  
              rowval = RotorDGV.CurrentCell.RowIndex  
          Catch ex As Exception  
          End Try  
  
          Dim col1 As String  
          Dim col3 As Date  
          col1 = RotorDGV.Rows(rowval).Cells(1).Value  
          col3 = RotorDGV.Rows(rowval).Cells(3).Value  
          connect = "provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\..\RailwayDatabase2.accdb"  
          query = "INSERT INTO tbl_shifts (EmployeeName, ShiftDate) VALUES(""" &amp; col1 &amp; """,""" &amp; col3 &amp; """);"  
          Con = New OleDb.OleDbConnection(connect)  
          comm = New OleDb.OleDbCommand(query, Con)  
          Con.Open()  
          comm.ExecuteNonQuery()  
  </code></pre>
  
  <p>The row I need deleted currently equals RotorDGV.CurrentCell.RowIndex or 'Rowval'.</p>
  
  <p>Can someone please tell me how to erase this record from both the table and datagridview upon clicking this button. Thank you </p>