Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried to populate data's in nested gridview. Am getting this error This constraint cannot be enabled as not all values have corresponding parent values. What is my error ? Help me to solve this.

This is my code
C#
validateDept.InitializeConnection();
        OleDbConnection connection = new OleDbConnection(validateDept.connetionString);

        OleDbDataAdapter AdapterCustomers = new OleDbDataAdapter(
         "SELECT EmployeeId, FirstName FROM Employee", connection);
        OleDbDataAdapter AdapterInvoices = new OleDbDataAdapter(
          "SELECT InvoiceId, InvoiceNumber, InvoiceDate, SalesPerson AS EmployeeId, Customername AS CustomerId, (Select CustomerName from Customer where Customer.CustomerId = NewInvoice_1.CustomerName) AS Customer_Name, DueDate, Tax, GrandTotal, CompanyId, InvoiceStatus FROM NewInvoice_1", connection);

        DataSet dataSet11 = new DataSet();
        //Create DataTable objects for representing database's tables
        AdapterCustomers.Fill(dataSet11, "Employee");
        AdapterInvoices.Fill(dataSet11, "Invoices");

        //Set up a master-detail relationship between the DataTables
        DataColumn keyColumn = dataSet11.Tables["Employee"].Columns["EmployeeId"];
        DataColumn foreignKeyColumn = dataSet11.Tables["Invoices"].Columns["EmployeeId"];
        dataSet11.Relations.Add("CustomerInvoice", keyColumn, foreignKeyColumn); // Getting error on this row

        //Bind the grid control to the data source
        gridControl1.DataSource = dataSet11.Tables["Employee"];
        gridControl1.ForceInitialize();

        //Assign a CardView to the relationship
        GridView cardView1 = new GridView(gridControl1);
        gridControl1.LevelTree.Nodes.Add("CustomerInvoice", cardView1);
        //Specify text to be displayed within detail tabs.
        cardView1.ViewCaption = "Invoice List of a Customer";

        //Create columns for the detail pattern View
        cardView1.PopulateColumns(dataSet11.Tables["Invoices"]);
Thnakyou,
Srihari
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900