Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Deleting a datarow from a table

Posted on 2005-04-11
3
Medium Priority
?
226 Views
Last Modified: 2010-04-07
Can sum1 tell me whats wrong with this please....

 Private Sub DeleteTitle()
        Try
            Dim DeleteCmdBuilder As New OleDbCommandBuilder(myDataAdapter)
            Dim mydeleterow = myDataTable.Rows
            myDataAdapter.Fill(myDataTable)

            For Each mydeleterow In myDataTable.Rows
                If mydeleterow("strJobTypeTAG") = cmbSrcTitle.Text Then
                    mydeleterow.delete()
                    myDataTable.AcceptChanges()
                    myDataAdapter.Update(myDataTable)
                End If
            Next             '-----------------------------------------------------------------------------

        Catch ex As OleDbException
            MsgBox(ex.ToString)
        End Try
    End Sub

I am trying to delete a row where the text in a combo box is the same as a field in the current row of the datatable.
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 1000 total points
ID: 13754564
You should not be calling .AcceptChanges, right after you call .delete().  When the dataadapter goes to update any changes, it won't see this change and skip over it.  Also, you should not be running .Update(myDataTable) on a row by row basis.  Delete all the rows in the datatable first, then .Update.  There is no sense, other than wasting CPU cycles to do it row by row.  The overall logic should be like this...

            For Each mydeleterow In myDataTable.Rows
                If mydeleterow("strJobTypeTAG") = cmbSrcTitle.Text Then
                    mydeleterow.delete()
                End If
            Next             '-----------------------------------------------------------------------------

            myDataAdapter.Update(myDataTable)
            myDataTable.AcceptChanges()
0
 

Author Comment

by:scm0sml
ID: 13754951
I'm getting concurrency violation: the delete command affected 0 records.

I've got this code:

Private Sub DeleteTitle()
        Try
            Dim DeleteCmdBuilder As New OleDbCommandBuilder(myDataAdapter)
            Dim mydeleterow = myDataTable.Rows
            myDataAdapter.Fill(myDataTable)

            For Each mydeleterow In myDataTable.Rows
                If mydeleterow("strJobTypeTAG") = cmbSrcTitle.Text Then
                    mydeleterow.delete()
                End If
            Next

            myDataAdapter.Update(myDataTable)
            myDataTable.AcceptChanges()

            End
        Catch e As Exception
            MsgBox(e.ToString)
        Catch ex As OleDbException
            MsgBox(ex.ToString)
        End Try
    End Sub

The record is actually being deleted but then this message is appearing.
Any ideas?
0
 

Author Comment

by:scm0sml
ID: 13754975
isnt there simply a currentRecord() that could be used to literally just say delete current record?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question