hi,
i work on a windows application and i use crystal report. i use this code to generate report from database:

private void imprimerB3button_Click(object sender, EventArgs e)
        {
            
            
            SqlCeConnection con = new SqlCeConnection();
            con.ConnectionString = @" Data source= |Datadirectory|\Database1.sdf";         
            Database1DataSet ds  = new Database1DataSet();
            
            SqlCeParameter paramNom = new SqlCeParameter("@nom", nomimprimerTextBox.Text);
            SqlCeDataAdapter da = new SqlCeDataAdapter("Select Personne.[Nom],Personne.[Prenom],Personne.[DateNaissance] from Personne where Personne.[Nom]=@nom", con);
            da.SelectCommand.Parameters.Add(paramNom);
            con.Open();
            da.Fill(ds,"Personne");
            
            B3Report   b3rpt = new B3Report();
            b3rpt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = b3rpt;
            crystalReportViewer1.Refresh();
        }

when i run the application i get this error message:"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
please help me and thanks

SqlCeDataAdapter da = new SqlCeDataAdapter("Select Personne.[Nom],Personne.[Prenom],Personne.[DateNaissance] from Personne where Personne.[Nom]=@nom", con);

I am not sure what SqlCeDataAdapter is but your code should look like this

SqlCeDataAdapter da = new SqlCeCommand("Select Personne.[Nom],Personne.[Prenom],Personne.[DateNaissance] from Personne where Personne.[Nom]=@nom", con);

if its throwing Null values you need to use the CASE WHEN.

SqlCeDataAdapter da = new SqlCeCommand("Select CASE WHEN Personne.[Nom] IS NULL THEN 'DefaultName' ELSE Personne.[Nom] END , CASE WHEN Personne.[Prenom] IS NULL THEN 'DefaultSurname' ELSE Personne.[Prenom] END ,CASE WHEN Personne.[DateNaissance] IS NULL THEN '19800101' ELSE Personne.[DateNaissance] END from Personne where Personne.[Nom]=@nom", con);

ofcourse it is good practice to only do the CASE WHEN where you think it may be null as this will increase query time. It is also possible to return '', except for date you have to return the same data type in THEN.

when i run the application i get this error message:"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
please help me and thanks

Ok sorry I just reread your problem, Look at your actual Data in the Database your the problem is arising from there.

You have a a NULL in a Non-Nullable column.
OR you have a Duplicate Primary Key
Check your relationships.

hi,
when i run the application i get this error message:"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
please help me and thanks

Open DataSet XSD (Typed dataset) and delete keys (Right click on table).

thanks a lot finito and adatapost you are right the problem is in my database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.