Question Problem with query attached to a tableadapter

Rex_Beginner

Member
Joined
Jan 23, 2009
Messages
5
Programming Experience
Beginner
I have a variable named SelectedOwner
dim SelectedOwner as int16

I have a query defined as a method attached to the PersonTableAdapter named GETOWNER()



- here's the query code attached to the PersonTableAdapter

GETOWNER(@PRidnumber)

SELECT PRIDNumber, PRFirstName, PRMiddleName, PRLastName, PRAddress, PRAddress2, PRCity, PRState, PRZipCode, PRPhone, PRPhone2, PREmail,
PRWebsite, PREname, PREPhone
FROM Person
WHERE (PRIDNumber = @pridnumber) AND (PRDesignation = 'OWNER')



In my code I display a message box showing the owner they've selected from the gridview on the previous form
The messagebox correctly displays the selected owner

MsgBox("You selected to Change Owner Number: " & stringtext)

SelectedOwner = CInt(stringtext)



The fields on my form are bound to the table adapter correctly


I then execute the following
PersonTableAdapter.GetOwnerRcd(SelectedOwner)


here is the message I'm getting.


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


I would understand this message if I were trying to insert a row into the table with a non-unique primary key but
the only thing my query does is select data and return a row. What am I missing. I'm really new at Visual Basic
VB studio also.

Any help would be appreciated.

Thanks
 
Some info in your post is incomplete or confusing. Assumptions:

Your tableadapter contains a standard "Query that returns rows"
You have named this query GetOwnerRcd()
The SQL of this query is SELECT PRIDNumber, PRFirstName, PRMiddleName, PRLastName, PRAddress, PRAddress2, PRCity, PRState, PRZipCode, PRPhone, PRPhone2, PREmail,
PRWebsite, PREname, PREPhone
FROM Person
WHERE (PRIDNumber = @pridnumber) AND (PRDesignation = 'OWNER')
or it is a stored procedure that returns this rowset
You opted not to create a "Fill a datatable" command, just a "Method that returns a datatable" command, or if you created a "Fill a datatable" youre not using it


You are calling your "Method that returns a datatable" like this: PersonTableAdapter.GetOwnerRcd(SelectedOwner)


1) Why? Youre not storing the resulting table. It's a useless operation
2) Youre not trying to insert any rows into database tables. The tableadapter is attempting to make a temporary data table, fill it with data and return it to you. The query is returning data that has been but into that temp table, but the data is in error because: 'One or more rows contain values violating non-null, unique, or foreign-key constraints'


I recommend that you capture the response from the comamnd:

Dim pdt as PersonDataTable = PersonTableAdapter.GetOwnerRcd(SelectedOwner)

And then investigate the problem using the immediate window:

?pdt(0).RowError
?pdt(1).RowError
?pdt(2).RowError
...

Eventually you will find the row in error, and what the error is. It will be something like:
"The value for PRIMARY_KEY_COLUMN is null"
or
"The value 'BLAHBLAHBLAH' in column SOME_TEXT exceeds the MaxLength limit for this column"
 

Latest posts

Back
Top