Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to retrieve the data by an id. But the following error occurs :

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

I checked every thing. Currently i am designing the system in mvc architecture. The query is working fine in DAL layer but when i want to access the query through webserver it returns the above error.

SQL
SELECT AttendeeName,AttendeeAddress,AttendeeContact,AttendeePayPalID,AttendeeDesignation,AttendeeUserID,AttendeePassword,AttendeeEmailID
From createAttendeeView
Where AttendeeID = @AttendeeID

And also my business logic code is :
C#
public DataSet wsGetAttendeeDetails(string AttendeeID)
        {
            DataSet ds = new DataSet();
            try
            {
                dt = attendeeview.getAttendeeDetailsByID(AttendeeID);

                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    ds.Tables.Add(dt);
                    return ds;
                }
            }
            catch (Exception ex)
            {
                ExceptionError er = new ExceptionError();
                er.errorMessage(ex.Message);
                throw;
            }      
        }

It does not enter into if loop and directly goes to catch and return the error. Please help me out of this.

Thanks..In advance
Posted
Updated 9-Jun-12 1:01am
v2

C#
public DataSet wsGetAttendeeDetails(string AttendeeID)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = new SqlCommand(string.Format("SELECT  AttendeeName, AttendeeAddress,AttendeeContact, AttendeePayPalID, AttendeeDesignation, AttendeeUserID FROM Attendee WHERE (AttendeeID = '{0}')", AttendeeID), con);
                con.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                dt.Load(sdr);
                con.Close();

                if (dt.Rows.Count == 0)
                {

                    DataTable table1 = new DataTable("Attendee");
                    table1.Columns.Add("Result");
                    table1.Rows.Add("Null");
                    ds.Tables.Add(table1);
                    return ds;
                }
                else
                {
                    ds.Tables.Add(dt);
                    return ds;
                }
            }
            catch (Exception)
            { 
                return null;
            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900