0

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...

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Unhnd_Exception
0

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
0

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...

0

I'm glad it helped you.

Mark the thread as solved.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.