Constraint Error

G

Guest

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?
 
M

Marina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top