none
MyDataSet.HierarchicalUpdate does not works correctly. RRS feed

  • Question

  • Hi

    in my dataSet designer, i have have 2 tables which have relationship together :

    the first table is 'Patients' and Pk is PatientCaseID

    the second table is 'Admisson' and have a fk which refer to Patients.PatientCaseID

    the property 'HierarchicalUpdate' set to 'true' but at run Time, if end-user insert a new Patient and admisson at the same time, i'm facing the general foreign key exception :

    The insert statement conflicts with the foreign key constraint .....

    Note : these 2 table only have relation. do i must to change some properties of my relation in dataSet designer ?

    can anybody help me how to solve this problem ?

    thanks in advance


    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    • Moved by Aspen VJ Thursday, May 19, 2011 6:18 AM (From:Visual C# General)
    Tuesday, May 17, 2011 8:48 PM

Answers

  • Hi Hamed,

    Welcome!

    The relationship in my sample is : Employee:Vacation=1:M the EId in Vaction table is FK:

     static void Main(string[] args)
        {
            DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.EmployeesTableAdapter ad1 = new DataSet1TableAdapters.EmployeesTableAdapter();
            ad1.Fill(ds.Employees);
            DataSet1TableAdapters.VacationTableAdapter ad2 = new DataSet1TableAdapters.VacationTableAdapter();
            ad2.Fill(ds.Vacation);
           DataSet1.EmployeesRow row=(DataSet1.EmployeesRow)ds.Employees.NewRow();
           row.EmployeeId = 10;
           row.Email = "ff";
           row.ModifyTime = DateTime.Now;
           row.Name = "ALan";
           row.Phone = "123";
           ds.Employees.AddEmployeesRow(row);
           DataSet1.VacationRow row1 = (DataSet1.VacationRow)ds.Vacation.NewRow();
           row1.Days = 1;
           row1.Id = 3;
           row1.EId = 10;
           row1.SetParentRow(row);
           ds.Vacation.AddVacationRow(row1);   
           ad1.Update(ds.Employees);
           ad2.Update(ds.Vacation);
         
        }
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 9:08 AM
    Moderator

All replies

  • Hi Hamed_1983,

    Based on your description, your issue is more related to ADO.Net dataset. So I will move this thread to ADO.Net DataSet forum to get better responses. Thanks for understanding.


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 19, 2011 6:18 AM
  • Any help ?
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Friday, May 20, 2011 8:10 PM
  • Hi Hamed,

    Welcome!

    The relationship in my sample is : Employee:Vacation=1:M the EId in Vaction table is FK:

     static void Main(string[] args)
        {
            DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.EmployeesTableAdapter ad1 = new DataSet1TableAdapters.EmployeesTableAdapter();
            ad1.Fill(ds.Employees);
            DataSet1TableAdapters.VacationTableAdapter ad2 = new DataSet1TableAdapters.VacationTableAdapter();
            ad2.Fill(ds.Vacation);
           DataSet1.EmployeesRow row=(DataSet1.EmployeesRow)ds.Employees.NewRow();
           row.EmployeeId = 10;
           row.Email = "ff";
           row.ModifyTime = DateTime.Now;
           row.Name = "ALan";
           row.Phone = "123";
           ds.Employees.AddEmployeesRow(row);
           DataSet1.VacationRow row1 = (DataSet1.VacationRow)ds.Vacation.NewRow();
           row1.Days = 1;
           row1.Id = 3;
           row1.EId = 10;
           row1.SetParentRow(row);
           ds.Vacation.AddVacationRow(row1);   
           ad1.Update(ds.Employees);
           ad2.Update(ds.Vacation);
         
        }
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 9:08 AM
    Moderator
  • Thanks Alan

    but i don't use tableAdapter.Update for every table, i'm using tableAdapterManager.UpdateAll to update my whole dataSet completely within a transaction.

    Your sample works good, but in my case, not works correctly!


    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Tuesday, May 24, 2011 12:54 PM
  • Hi Hamed,

    I didn't find any error with tableAdapterManager.UpdateAll method on my computer:

     DataSet1 ds = new DataSet1();
          DataSet1TableAdapters.TableAdapterManager ta = new DataSet1TableAdapters.TableAdapterManager();
          ta.EmployeesTableAdapter = new DataSet1TableAdapters.EmployeesTableAdapter();
          ta.VacationTableAdapter = new DataSet1TableAdapters.VacationTableAdapter();
         //  DataSet1TableAdapters.EmployeesTableAdapter ad1 = new DataSet1TableAdapters.EmployeesTableAdapter();
         // ad1.Fill(ds.Employees);
         // DataSet1TableAdapters.VacationTableAdapter ad2 = new DataSet1TableAdapters.VacationTableAdapter();
         // ad2.Fill(ds.Vacation);
          ta.VacationTableAdapter.Fill(ds.Vacation);
          ta.EmployeesTableAdapter.Fill(ds.Employees);
          DataSet1.EmployeesRow row = (DataSet1.EmployeesRow)ds.Employees.NewRow();
          row.EmployeeId = 11;
          row.Email = "ff";
          row.ModifyTime = DateTime.Now;
          row.Name = "ALan";
          row.Phone = "123";
          ds.Employees.AddEmployeesRow(row);
          DataSet1.VacationRow row1 = (DataSet1.VacationRow)ds.Vacation.NewRow();
          row1.Days = 1;
          row1.Id = 4;
          row1.EId = 11;
          row1.SetParentRow(row);
          ds.Vacation.AddVacationRow(row1);
          ta.UpdateAll(ds);
          //ad1.Update(ds.Employees);
          //ad2.Update(ds.Vacation);
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 30, 2011 3:10 AM
    Moderator