Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am writing a code that calls a column from a dataset using a SQL query. I use two parameters to identify which rows to select. One is the ProductSerialNumber, and the other is a datetimestamp. See my SQL query below

    Select TestStation FROM tblData
    WHERE ProductSerialNumber = ? AND Datetimestamp = ?

In the dataset's datatable the productserialnumber is formatted as text, and the other is formatted as a date (as you would expect).

In my vb.net code, I grab the Datetimestamp from another source (don't ask why, the only thing you need to know is that it grabs a valid datetimestamp, dimensioned as a date, that matches exactly with the tblData's entry) and I use the premade query to generate a datatable. The query is a Fill query called "TestStationLookUp"

my vb.net code looks like this

    Dim dt as new dataset.tbldataDataTable
    Dim dta As New DataSetTableAdapters.tbldataTableAdapter
    Dim ProductSerialNumber as string = "XXXXXX"
    Dim DateTimeStamp as date = SomeDateVariable
    dta.TestStationLookUp(dt, ProductSerialNumber, DateTimeStamp)

It is here that the code tells me:

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

       Line 7366:                dataTable.Clear
       Line 7367:            End If
Error: Line 7368:            Dim returnValue As Integer = Me.Adapter.Fill(dataTable)
       Line 7369:            Return returnValue
       Line 7370:        End Function

I cannot understand why this error arises, as everything is dimensioned the way it should be. This exact code setup works elsewhere in my code (except it doesn't use a date), but this specific piece won't work.

Also, if I go to the dataset in my solution, I can use the "preview data" on this query and type in the EXACT same parameters (the ProductSerialNumber and DateTimeStamp that match the record in the table AND what I use in my vb code) and it will give me produce the table I want.

Can anyone assist?

share|improve this question
I am sorry, I don't understand your comment. dta.TestStationLookUp is the TableAdapter's query. I provided the query code above (I just changed the name of things for confidential reasons) – user2646256 Aug 2 at 15:30
What if you increase the size of your field? What size do you currently have it to? – Hanlet Escaño Aug 2 at 15:50
add comment (requires an account with 50 reputation)

1 Answer

up vote 0 down vote accepted

This error means that you are trying to access not valid unique id "ProductSerialNumber", maybe it does not exist

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

Instead of passing the variable that comes from dataset ,pass a valid number that you are sure it exists in database

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.