Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 C#
Hello
 
Can any body help me?
 
I bind a dataset to combobox. (siteName, siteId) At the run time I got following error.
 
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
 
If siteName have less char then no problem. But if it is more than 25+ then it raise error.
 
I set datatype of siteName varchar(MAX)
 
Record save in database but at the time fetching it raise error (i.e.(in load method) I am not written any code. Just regular binding data.
 
When I run query in query builder it is executed successfully at the point when we create dataset. How this can be possible if it have non-null, unique, or foreign-key constraints?
Posted 30-Nov-09 2:18am
Edited 1-Dec-09 8:24am
v4
Comments
Member 10367533 at 25-Apr-14 2:53am
   
I got same error msm, i have completed my project , finally create crystal report as fetch record from Emp_sal table, I got error when I change 2 field’s data type int to numeric (18,0),it was not reset when I change numeric to int data type……
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

This error was also showing in my project, using Visual Studio 2010. I tried other solutions posted in other blogs, but no luck at all because the problem had nothing to do with fields size, table key fields definition, constraints or the EnforceConstraints dataset variable.
 
In my case I have a .xsd object which I put there during the project design time (in the Data Access Layer). As you drag your database table objects into the Dataset visual item, it reads each table definition from the underlying database and copies the constraints into the Dataset object exactly as you defined them when you created the tables in your database (SQL Server 2008 R2 in my case). This means that every table column created with the constraint of "not null" or "foreign key" must also be present in the result of your SQL statement or stored procedure.
 
After I included all the constrained columns (not null, primary key, foreign key, etc) into my queries the problem disappeared completely.
 
Perhaps you don't need all the table columns to be present in the query/store procedure result, but because the constraints are still applied the error is shown if some constrained column does not appear in the result.
 
Hope this helps someone else.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Can you try this function
 
 Public Function getSP2DataTable(ByVal spName As String, ByVal paramName() As String, ByVal paramValue() As String)
        On Error GoTo ErrorHappening
        Dim rtnDT As New DataTable
        Dim StartTime As Date = TimeOfDay
        Dim endTime As Date
        Using tmpDT As New DataTable
            Using myDB As New MySql.Data.MySqlClient.MySqlConnection(ConString)
                myDB.Open()
                Using myCMD As New MySql.Data.MySqlClient.MySqlCommand(spName, myDB)
                    myCMD.CommandType = CommandType.StoredProcedure
                    For i As Byte = 0 To paramName.GetUpperBound(0)
                        myCMD.Parameters.AddWithValue(paramName(i), paramValue(i))
                    Next
                    Dim myResult As IAsyncResult = myCMD.BeginExecuteReader
                    'Dim myRD As MySql.Data.MySqlClient.MySqlDataReader = myCMD.EndExecuteReader(myResult)
                    'tmpDT.Load(myRD, LoadOption.OverwriteChanges)
                    'myRD.Close()
                    Using myDataSet As New DataSet
                        Using myAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter(myCMD)
                            myAdapter.Fill(myDataSet)
                            rtnDT = myDataSet.Tables(0)
                        End Using
                    End Using                    
endTime = TimeOfDay
                    frmMain.scriptTime.Text = "Last procedure name [" & spName & "] was executed in " & DateDiff(DateInterval.Second, StartTime, endTime) & " Second(s)."
                    myDB.Dispose()
                    myCMD.Dispose()
                End Using
            End Using
            Return rtnDT
        End Using
ErrorHappening:
        errorInfo()
    End Function
 
I was used the DataSet instread of DataReader.
Sorry for less English typing skill.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Dont know what exactly the problem is. But I guess, some foreign key violation has taken place.
 
Use Sql Server Profiler to find what exactly the insert statement it generates when you pass 25+ characters.
 
I think there should be some problem in insert statement when you make it 25+.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

What i can make out from the error is that your table return some duplicate data for a column which is declared as primary key in your typed dataset. Remove the key attribute( not recommended since it actually defies the basic logic of a combo control) D'Oh! | :doh: D'Oh! | :doh: D'Oh! | :doh: .
 
I would recommend you to verify your data first.Thumbs Up | :thumbsup:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

I had this problem, too.
 
Simply before calling
myAdapter.Fill(myDataSet)
add this line of code
myDataSet.Clear();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There must be other code in there that is causing this. How do you do the data binding ? Because if the data is IN the database, it can't violate any constraint in the data layer. What code causes the error ?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Well, real programmers write data layers. Using that automatic rubbish, you're at the mercy of Microsoft and debugging becomes very difficult. I agree with the other reply, you need to some how work out what SQL is being generated and debug from there.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

I had this problem, too
But
there is another way :
if you query contains some selection from two or more table having relations
select your data from you data base with "sp" then use it
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

Hi Dears;
You Must Used These Code Before Fill DataTable :
 
var dt = new System.DataTable.DataTable();
dt.Clear();
dt.Rows.Clear();
dt.Columns.Clear();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

I was looking at this problem and it occurred to me that any data item not returned to a tableadapter from the associated stored procedure may cause this error. I deleted the column that was not being returned from the list of expected data items. I made another test and the error was gone. This error was do to the null value that resulted when the data item was not returned from the stored procedure.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 31 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100