TableAdapter.update not working for a relationed table

db Bahrain
  • 13 years ago
    Hi Guys,
    need some help here,
    Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning,
    the datatable has a relation with another table, the relationship is on to many.
    in the dataset designer I configured it to Relation only,
    the database is in mdf format, I can update my records in the access file, and can do it also in the server explorer, but not when from my form, instead i get an oledb exception.
    here is the exception:
    System.Data.OleDb.OleDbException was unhandled
    ErrorCode=-2147467259
    Message="The record cannot be deleted or changed because table 'tblVacations' includes related records."
    Source="Microsoft JET Database Engine"
    StackTrace:
    at System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(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.UpdateFromDataTab le(DataTable dataTable, DataTableMapping tableMapping)
    at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
    at HRS.HRS2007DataSetTableAdapters.tblStaffTableAdapt er.Update(tblStaffDataTable dataTable) in C:\Users\Jassim\Documents\Visual Studio 2005\Projects\HRS\HRS\HRS2007DataSet.Designer.vb:l ine 4406
    at HRS.frmStaff.btnSave_Click(Object sender, EventArgs e) in C:\Users\Jassim\Documents\Visual Studio 2005\Projects\HRS\HRS\frmStaff.vb:line 35
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[] commandLine)
    at HRS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
    at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()


    can anyone help with this matter
    Thanks
  • 13 years ago
    Either you have to edit your relationship in the database to cascade delete operations, so that child records will be deleted automatically, or else you have to delete the child records first yourself.
  • 13 years ago

    I had to delete both parent and child records and cascade the delete and update in the relationship, it works perfectly now,

     Thanks for the help

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks