I have the folloing code using OleDB to manipulate an Access database:

Dim adpMasterRecipe As OleDb.OleDbDataAdapter
Dim dsMasterRecipe As New System.Data.DataSet

adpMasterRecipe = New OleDb.OleDbDataAdapter("SELECT * FROM tblMasterRecipe WHERE MasterID = @MasterID", My.Settings.RecipesConnectionString)
adpMasterRecipe.SelectCommand.Parameters.AddWithValue("@MasterID", iRecipeNumber)
adpMasterRecipe.Fill(dsMasterRecipe)

If dsMasterRecipe.Tables(0).Rows.Count > 0 Then
    dsMasterRecipe.Tables(0).Rows(0).Delete()
    dsMasterRecipe.AcceptChanges()
    adpMasterRecipe.Update(dsMasterRecipe)
End If

The problem is that the row is not actually removed from the actual database...

Member Avatar for Unhnd_Exception

Everyone loves them some DataSets and DataTables.

I deal with the DB directly. Not a make-believe copy.

This will communicate directly with the DB and remove the records.

Dim Connection As New OleDbConnection("...")
 Dim Command As New OleDbCommand

 Command.Connection = Connection
 Command.CommandText = "Delete From tblMasterRecipe WHERE MasterID = @MasterID"
 Command.Parameters.AddWithValue("@MasterID", 1) '1 = your iRecipeNumber
 Try
     Connection.Open()
     Command.ExecuteNonQuery()
     Connection.Close()
 Catch ex As Exception
      MsgBox(ex.Message)
 Finally
      Connection.Dispose()
      Command.Dispose()
 End Try

Unhnd_Exception,

This is exactly what I was looking for. The code was originally written in DAO and everyone told me I needed to update the program to ADO.Net using DataSets and DataTables. This approach is much cleaner and easier to understand...

Member Avatar for Unhnd_Exception

I'm glad it helped you.

Mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.