1

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?

2
  • 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) Commented Aug 2, 2013 at 15:30
  • What if you increase the size of your field? What size do you currently have it to? Commented Aug 2, 2013 at 15:50

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.