none
can't delete a row using TableAdapter.update! RRS feed

  • Question

  • Hello,

    I am working on the RSS Reader project from the videos.

    When I try to update the table, when I delete a row, or sometimes when I add rows, I have the following error:

    "Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."

    And the full one:

     System.InvalidOperationException was unhandled
      Message="Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
      Source="System.Data"
      StackTrace:
           at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
           at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
           at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
           at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
           at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
           at Searcher.RssDataSetTableAdapters.NewsItemsTableAdapter.Update(RssDataSet dataSet)
           at Searcher.News.deleteNewsItems(Int32 channelID)
           at Searcher.News.DeleteChannel()
           at Searcher.News.ToolStripButton6_Click(Object sender, EventArgs e)
           at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
           at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
           at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ToolStrip.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at Searcher.My.MyApplication.Main(String[] Args)
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    What should I do??

     

    Thanks,

    Ofir.

    • Moved by VMazurModerator Tuesday, August 3, 2010 10:32 AM (From:ADO.NET Managed Providers)
    Wednesday, December 28, 2005 6:35 PM

Answers

  • Hi,

    As I can see, you are using a TableAdapter which means that your are doing Designer Data Binding. Just check your .xsd file and look at your tableadapter and check its properties and Check if the DeleteCommand has been specified. Coz the error implies that the DeleteCommand of your TableAdapter is not properly defined.

     

     

    cheers,

    Paul June A. Domag

    Thursday, December 29, 2005 6:36 PM

All replies

  • This is the code that don't work at all (to Delete a row):

    Private Sub deleteNewsItems(ByVal channelID As Integer)

    ' For the given Channel, delete all associated NewsItems.

    Dim newsItems() As RssDataSet.NewsItemsRow

    newsItems = RssDataSet1.NewsItems.Select("ChannelID = '" & channelID.ToString() & "'")

    If newsItems.Length = 0 Then

    Return

    End If

    Dim newsItem As RssDataSet.NewsItemsRow

    For Each newsItem In newsItems

    newsItem.Delete()

    Next

    Dim rowsAffected As Integer = 0

    rowsAffected = NewsItemsTableAdapter.Update(RssDataSet1) '***** THIS IS WHERE THE ERROR IS.

    End Sub

     

     

    Ofir.

    Wednesday, December 28, 2005 6:44 PM
  • Hi,

    As I can see, you are using a TableAdapter which means that your are doing Designer Data Binding. Just check your .xsd file and look at your tableadapter and check its properties and Check if the DeleteCommand has been specified. Coz the error implies that the DeleteCommand of your TableAdapter is not properly defined.

     

     

    cheers,

    Paul June A. Domag

    Thursday, December 29, 2005 6:36 PM
  •  

    The Delete command isn't generated if you forgot to give your table a primary key.

     

    • Proposed as answer by Er1k Tuesday, June 1, 2010 8:31 PM
    Thursday, January 12, 2006 5:48 PM
  • great! it works... thnx!
    Monday, August 2, 2010 7:46 PM