检索数据集时出现问题 [英] Problem in retrieving the data set

查看:65
本文介绍了检索数据集时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想通过ID检索数据.但是发生以下错误:

System.Data.ConstraintException:无法启用约束.一或多个行包含违反非null,唯一或外键约束的值.

我检查了每件事.目前,我正在设计MVC体系结构中的系统.该查询在DAL层中工作正常,但是当我想通过Web服务器访问查询时,它会返回上述错误.

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.

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


我的业务逻辑代码也是:


And also my business logic code is :

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;
            }      
        }


它不会进入if循环,而是直接捕获并返回错误.请帮助我.

谢谢..预先


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

推荐答案

看看以下这些可以解决问题:
操作方法:疑难解答未能启用约束.一或多个行包含违反非null的值 [ http: //www.devnewsgroups.net/adonet/t14842-failed-enable-constraints-one-more-rows-contain-values-violating-non-null-unique-foreign.aspx [ http://www.dotnet247.com/247reference/msgs/21/108864.aspx [ ^ ]
http://weblogs.asp.net/dmarsh/archive/2002/06/16/492.aspx [ ^ ]
http://social.msdn.microsoft.com /Forums/zh-CN/Vsexpressvb/thread/27aec612-5ca4-41ba-80d6-0204893fdcd1/ [
Have a look at these to troubleshoot:
ERROR : Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints [^]
How to: Troubleshoot "Failed to enable constraints. One or more rows contain values violating non-null[^]

Similar discussions:
http://www.devnewsgroups.net/adonet/t14842-failed-enable-constraints-one-more-rows-contain-values-violating-non-null-unique-foreign.aspx[^]
http://www.dotnet247.com/247reference/msgs/21/108864.aspx[^]
http://weblogs.asp.net/dmarsh/archive/2002/06/16/492.aspx[^]
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/27aec612-5ca4-41ba-80d6-0204893fdcd1/[^]


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;
            }
        }


这篇关于检索数据集时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆