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?