473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Constraint Error

I have a SQL table (tblUser) that has the following design:

Col Dtype Len Nulls

UserID varchar 10 0
Password varchar 10 0
FirstName varchar 10 0
LastName varchar 10 0
Type char 5 0
DateEntered datetime 8 1
EnteredBy varchar 50 1

I have 1 record in this table

When I run my code I receive this error:

Exception Details: System.Data.ConstraintException: Failed to enable
constraints. One or more rows contain values violating non-null, unique, or
foreign-key constraints.

Source Error:

Line 129: SqlDataAdapter1.SelectCommand = cmdUser
Line 130: SqlDataAdapter1.MissingSchemaAction =
MissingSchemaAction.AddWithKey
Line 131: SqlDataAdapter1.Fill(DsUserList1)
Line 132: dgUser.DataSource = DsUserList1
Line 133: dgUser.DataBind()

Source File: c:\inetpub\wwwroot\ITApplications\UserList.aspx.vb Line: 131

My code is:

Dim cmdUser As New SqlCommand
Dim sSelect As String = "SELECT UserID, FirstName + ' ' + LastName AS Name,
Type FROM tblUser ORDER BY UserID"
cmdUser.CommandText = sSelect
cmdUser.Connection = SqlConnection1
SqlDataAdapter1.SelectCommand = cmdUser
SqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey
SqlDataAdapter1.Fill(DsUserList1)
dgUser.DataSource = DsUserList1
dgUser.DataBind()

My select statement works in Query Analyzer. Does anyone know why this is
happening?

Nov 19 '05 #1
1 1321
What is DsUserList1? I'm guess it's a dataset, but does it have some sort of
constraints defined on it?

Basically, the error is not happening at the database level. The problem is
the object you are trying to put the results of the query into.

"JackO" <Ja***@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
I have a SQL table (tblUser) that has the following design:

Col Dtype Len Nulls

UserID varchar 10 0
Password varchar 10 0
FirstName varchar 10 0
LastName varchar 10 0
Type char 5 0
DateEntered datetime 8 1
EnteredBy varchar 50 1

I have 1 record in this table

When I run my code I receive this error:

Exception Details: System.Data.ConstraintException: Failed to enable
constraints. One or more rows contain values violating non-null, unique,
or
foreign-key constraints.

Source Error:

Line 129: SqlDataAdapter1.SelectCommand = cmdUser
Line 130: SqlDataAdapter1.MissingSchemaAction =
MissingSchemaAction.AddWithKey
Line 131: SqlDataAdapter1.Fill(DsUserList1)
Line 132: dgUser.DataSource = DsUserList1
Line 133: dgUser.DataBind()

Source File: c:\inetpub\wwwroot\ITApplications\UserList.aspx.vb Line:
131

My code is:

Dim cmdUser As New SqlCommand
Dim sSelect As String = "SELECT UserID, FirstName + ' ' + LastName AS
Name,
Type FROM tblUser ORDER BY UserID"
cmdUser.CommandText = sSelect
cmdUser.Connection = SqlConnection1
SqlDataAdapter1.SelectCommand = cmdUser
SqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey
SqlDataAdapter1.Fill(DsUserList1)
dgUser.DataSource = DsUserList1
dgUser.DataBind()

My select statement works in Query Analyzer. Does anyone know why this is
happening?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
0
by: Ron | last post by:
Mandatories: Ver 7.3.4, Redhat Linux 8.0, P4, 2GB RAM I want to add a 'nullable' foreign key to a column in a table. I have tables "company" and "project" which may be related by...
0
by: Tetsuji Ueda | last post by:
Hello, I'm currently porting an application using some other DB to MySQL. The database in question has several tables with foreign key relations. The application is written such that, on table...
0
by: Jeremiah Jacks | last post by:
I just upgraded to MySQL 4.0.14-standard for RedHat Linux and am using = the pre-compiled binaries. I have a database with INNODB tables. When I insert a row into one of the child tables, I get...
1
by: Mike Hunter | last post by:
(Please CC me on any replies as I'm not on the list) Hi, After a recent power failure, a program that uses a pgsql backend (netdisco) started to send me nastygrams. I tried the author's...
4
by: Jethro Guo | last post by:
C++ template use constraint by signature,It's very flexible to programmer but complex for complier, and at most time programmer can not get clear error message from complier if error occur. C#...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
4
by: antpal | last post by:
I am not sure exactly what i am doing run but when I run this code in sql plus i get constraint error on most of my tables except author and books table. Please help I am new to Programming in...
15
by: Frank Swarbrick | last post by:
I have the following three tables DROP TABLE CALLTRAK.SERVICE_CODES @ CREATE TABLE CALLTRAK.SERVICE_CODES ( CODE CHAR(1) NOT NULL , CONSTRAINT SERVICE_CODES_PK PRIMARY KEY (CODE) ,...
2
by: rorajoey | last post by:
Violation of UNIQUE KEY constraint 'IX_surveyQuestions'. Cannot insert duplicate key in object 'dbo.surveyQuestions'. This might seem like a simple matter of trying to insert a row with ID=20 when...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.