Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:01:17+00:00 2026-06-14T07:01:17+00:00

I searched a lot, but could not find the solution. I get the error:

  • 0

I searched a lot, but could not find the solution.

I get the error:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I run DataTable.GetErrors() and see that some columns are set to Not NULL in SQL Compact Edition Database. And these columns are used in LEFT OUTER JOIN query so they are null when the query is run. (I can get the results when i run the query in Server Explorer in VS).
The error occurs when trying to load the data in Datatable:

using (SqlCeCommand Cmd = new SqlCeCommand("Query HERE", "Connection HERE"))
                {
                    C.Open();
                    using (SqlCeDataReader Rdr = Cmd.ExecuteReader())
                    {
                        DataTable DT = new DataTable();
                        DT.Load(Rdr);
                        return DT;
                    }
                }

I tried so many solutions to overcome this however i was not able to solve it. I know about “EnforceConstraints” however as i do not use any dataset, i can not change that property.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:01:18+00:00Added an answer on June 14, 2026 at 7:01 am

    I managed to solve this by getting the schema of the table, iterating through the rows of the schema table (which are columns of the actual table) and creating a column with same properties as the schema column (only difference is setting new column’s AllowDBNull to true and Unique and AutoIncrement to false) and finally adding the new column to a fresh datatable which will later be filled with data of our actual table (by the help of a DataReader to get only data and not the schema).

    Here is the code:

    using (SqlCeConnection C = new SqlCeConnection(DBStr))
                using (Cmd)
                {   //using SqlCeCommand
                    Cmd.Connection = C;
                    C.Open();
                    using (SqlCeDataReader Rdr = Cmd.ExecuteReader())
                    {
                        //Create datatable to hold schema and data seperately
                        //Get schema of our actual table
                        DataTable DTSchema = Rdr.GetSchemaTable();
                        DataTable DT = new DataTable();
                        if (DTSchema != null)
                            if (DTSchema.Rows.Count > 0)
                                for (int i = 0; i < DTSchema.Rows.Count; i++)
                                {
                                    //Create new column for each row in schema table
                                    //Set properties that are causing errors and add it to our datatable
                                    //Rows in schema table are filled with information of columns in our actual table
                                    DataColumn Col = new DataColumn(DTSchema.Rows[i]["ColumnName"].ToString(), (Type)DTSchema.Rows[i]["DataType"]);
                                    Col.AllowDBNull = true;
                                    Col.Unique = false;
                                    Col.AutoIncrement = false;
                                    DT.Columns.Add(Col);
                                }
    
                        while (Rdr.Read())
                        {
                            //Read data and fill it to our datatable
                            DataRow Row = DT.NewRow();
                            for (int i = 0; i < DT.Columns.Count; i++)
                            {
                                Row[i] = Rdr[i];
                            }
                            DT.Rows.Add(Row);
                        }
                        //This is our datatable filled with data
                        return DT;
                    }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched around a lot for a solution, but could not find any.
i searched a lot on NET, to get the solution, but i could not
I have searched a lot but I could not find any good solution to
I searched a lot but could not find a way to dump table relations
I have searched a lot but i could not find any way to convert
i have searched a lot but could not find the exact way to do
I have searched a lot and tried much but I can not find the
I've searched a lot but could not solve this problem. I am generating PDF
I searched a lot but I didn't find a solution for my problem. I
I searched many places but could not find a complete working example of implementation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.