Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForeignKey constraint impropered performing when added the data in relatedview with DataRelation #2292

Open
SaravananAyyanar opened this issue Nov 5, 2019 · 1 comment

Comments

@SaravananAyyanar
Copy link

@SaravananAyyanar SaravananAyyanar commented Nov 5, 2019

Problem description:
1."ForeignKeyConstraint Employee requires the child key values () to exist in the parent table " exception thrown when given the value is not equal foreignkey. (Refer the attached screenshot1)
2.Exception not thrown when given the value is equal foreignKey and also added the data correctly in relatedview.
3.Exception not thrown when given the value is null for foreign key and also not added the data in relatedview.
(Refer the screenshot2)
Can you please given the proper solution for it(3rd point).

Coding:

         DataTable employeeCollection = new DataTable();

        DataTable employeeCollection1 = new DataTable();
        DataSet ds = new DataSet();
        DataTable dataTable;

         dataTable = this.GetDataTable();

	 public DataTable GetDataTable()
           {
            employeeCollection.Columns.Add("EmployeeID", typeof(int));            
            employeeCollection.Columns.Add("EmployeeName", typeof(string));
            employeeCollection.Columns["EmployeeName"].ColumnName = "Employee Name";
            employeeCollection.Columns.Add("CustomerID", typeof(string));
            employeeCollection.Columns["CustomerID"].ColumnName = "Customer ID";
            employeeCollection.Columns.Add("Country", typeof(string));
            employeeCollection.Columns.Add("Date", typeof(DateTime));

            employeeCollection.Rows.Add(1001, "Belgim", "Yhgtr", "US", new DateTime(2019, 10, 15));
            employeeCollection.Rows.Add(1002, "Oliver", "Johanesberg", "UK", new DateTime(2018, 11, 29));            
            employeeCollection.Rows.Add(1004, "James", "Yhgtr", "Chicago", new DateTime(2016, 5, 13));
            employeeCollection.Rows.Add(1005, "Beverton", "Bergs", "Spain", new DateTime(2015, 6, 29));                        
            employeeCollection.Rows.Add(1009, "Dintin", "Britain", "Britain", new DateTime(2014, 3, 10));            
            employeeCollection.Rows.Add(1010, "Joysie", "Oregon", "China", new DateTime(2012, 11, 11));            
            employeeCollection.Rows.Add(1017, "George", "Oregon", "SwitzerLand", new DateTime(2017, 7, 17));
            

            employeeCollection1.Columns.Add("EmployeeID", typeof(int));            
            employeeCollection1.Columns.Add("Country", typeof(string));
            employeeCollection1.Columns.Add("Date", typeof(DateTime));

            employeeCollection1.Rows.Add(1001,"US", new DateTime(2019, 10, 15));
            employeeCollection1.Rows.Add(1002,"UK", new DateTime(2018, 11, 29));
            employeeCollection1.Rows.Add(1004,"Chicago", new DateTime(2016, 5, 13));
            employeeCollection1.Rows.Add(1005,"Spain", new DateTime(2015, 6, 29));
            employeeCollection1.Rows.Add(1009,"Britain", new DateTime(2014, 3, 10));
            employeeCollection1.Rows.Add(1010,"China", new DateTime(2012, 11, 11));
            employeeCollection1.Rows.Add(1017,"SwitzerLand", new DateTime(2017, 7, 17));

            ds.Tables.Add(employeeCollection);
            ds.Tables.Add(employeeCollection1);

            ds.Relations.Add(new DataRelation("Employee", ds.Tables[0].Columns["Country"],   ds.Tables[1].Columns["Country"]));
  return ds.Tables[0];
}

 private void button1_Click(object sender, EventArgs e)
  {
            DataTable parentDataTable = dataTable;
            
            DataView relatedView = parentDataTable.DefaultView[0]["Employee"] as DataView;

            System.Data.DataRow dataRow = relatedView.Table.NewRow();
            dataRow["EmployeeID"] = 101;
            dataRow["Country"] = null;
            relatedView.Table.Rows.Add(dataRow);            
}

screenshot1

screenshot1

@RussKie

This comment has been minimized.

Copy link
Member

@RussKie RussKie commented Nov 6, 2019

Thank you, but it appears you have skipped the bug template and, thus, a number of important pieces of information were left omitted - without those we will be unable to provide any help.
The information we require is captured here: https://github.com/dotnet/winforms/edit/master/.github/ISSUE_TEMPLATE/bug_report.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.