DELETE a row from a datatable

I have a dataAdapter that fills a datatable.
I find the value of the primary key for the row to be deleted
I then attempt to delete the row and update the database

but nothing happens on the update
here is my code

Dim TaskID As Integer
        Dim dr As DataRow
        Dim dt As New DataTable
        Dim prm(0) As DataColumn
        Try
            daTask.Fill(dt)
        prm(0) = dt.Columns("TASK_ID")
        dt.PrimaryKey = prm

        TaskID = Me.grdV_DEPARTMENT_TASK.Item(Me.grdV_DEPARTMENT_TASK.CurrentRowIndex, 5)
        dr = dt.Rows.Find(TaskID)
            dr.Delete()
            dt.Rows.Remove(dr)
            dt.AcceptChanges()
            Dim result = daTask.Update(dt)

        MsgBox(result)
justinwood88Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

apumaCommented:
I am not much of an expert   but this is the code i use to delete a record

Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
        Dim intcurrentrecord As Integer = Me.BindingContext(DsStoreAd1, "tblstoread").Position
        DsStoreAd1.tblStoreAd.Rows(intcurrentrecord).Delete()
        mblnDirty = True
        DBStoreAd.Update(DsStoreAd1) 'update data file
        'reload dataset   this will enable bindingcontext events
        DBStoreAd.Fill(DsStoreAd1)
        'position in datsaet                           = previous record
        Me.BindingContext(DsStoreAd1, "tblstoread").Position = intcurrentrecord - 1
       


perhaps you need to reload you datatable??

justinwood88Author Commented:
I figured it out I used this code thanks for the help any way

Dim TaskID As Integer
        Dim dr As DataRow
        Dim dt As New DataTable
        Try
            dt = Me.DstheTask1.Tables("TASK")
            TaskID = Me.grdV_DEPARTMENT_TASK.Item(Me.grdV_DEPARTMENT_TASK.CurrentRowIndex, 5)
            dr = dt.Rows.Find(TaskID)
            dr.Delete()
            dr.EndEdit()

            daTask.Update(DstheTask1, "TASK")

            Dim pos = Me.BindingContext(objdsTask, "Bus_Cent_Dept").Position
            Me.LoadDataSet()
            Me.BindingContext(objdsTask, "Bus_Cent_Dept").Position = pos
            Me.objdsTask_PositionChanged()

        Catch ex As Exception
            MsgBox(ex.Message)
        Catch d As SqlClient.SqlException
            MsgBox(d.Message)

Please refund my points
CetusMODCommented:
PAQed with points refunded (250)

CetusMOD
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.