Error Meassage

Last post 04-22-2007 3:11 PM by TATWORTH. 5 replies.

Sort Posts:

  • Error Meassage

    04-19-2007, 2:20 PM
    • Loading...
    • semsem0
    • Joined on 12-26-2006, 8:28 PM
    • Egypt
    • Posts 136

     i make abussines class and then i try to use object data sourse  to view data in data in grid view

    hi gave me this error meassage idont know what to do?

     Server EROOR 

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

    Hope beSt ThIng Be ArouNd You
  • Re: Error Meassage

    04-19-2007, 3:28 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 8:34 AM
    • England
    • Posts 6,552
    Are you returning a data table instead of a dataset. I would not expect a dataset will not have this problem.
    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Error Meassage

    04-22-2007, 11:24 AM
    • Loading...
    • semsem0
    • Joined on 12-26-2006, 8:28 PM
    • Egypt
    • Posts 136

    yea this is the bussines class that i made :

     

    [System.ComponentModel.

    DataObject]

    public

    class StaffsBLL

    {

    private staffTableAdapter _StaffsAdapter = null;

    protected staffTableAdapter Adapter

    {

    get {

    if (_StaffsAdapter == null)

    _StaffsAdapter =

    new staffTableAdapter();

    return _StaffsAdapter;

    }

    }

    [System.ComponentModel.

    DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]

    public Akhbar.staffDataTable GetData()

    {

    return Adapter.GetData();

    }

    [System.ComponentModel.

    DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]

    public bool AddStaffs(int StaffID, string Name, int ? Type_ID)

    {

    Akhbar.staffDataTable Staffs = new Akhbar.staffDataTable();

    Akhbar.staffRow Staff = Staffs.NewstaffRow();

    Staff.StaffID = StaffID;

    Staff.Name = Name;

    if (Staff.Type_ID == null) Staff.SetType_IDNull();

    else Staff.Type_ID = Type_ID.Value;

    // Add the new

    Staffs.AddstaffRow(Staff);

    int rowsAffected = Adapter.Update(Staffs);

     

    // Return true if precisely one row was inserted,

    // otherwise false

    return rowsAffected == 1;

    }

    [System.ComponentModel.

    DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]

    public bool UpdataStaffs(int StaffID, string Name, int ? Type_ID)

    {

    Akhbar.staffDataTable Staffs = Adapter.GetStaffByStaffID(StaffID);

    if(Staffs.Count==0)

    // no matching record found, return false

    return false;

    Akhbar.staffRow Staff = Staffs[0];

    Staff.StaffID = StaffID;

    Staff.Name = Name;

    if (Staff.Type_ID == null) Staff.SetType_IDNull();

    else Staff.Type_ID = Type_ID.Value;

     

    int rowsAffected = Adapter.Update(Staff);

    // Return true if precisely one row was updated,

    // otherwise false

    return rowsAffected == 1;

    }

    [System.ComponentModel.

    DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]

    public bool DeleteStaff(int StaffID)

    {

    int rowsAffected = Adapter.Delete(StaffID);

    return rowsAffected == 1;

    }

     

    }

    Hope beSt ThIng Be ArouNd You
    Filed under:
  • Re: Error Meassage

    04-22-2007, 12:41 PM
    Answer
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 8:34 AM
    • England
    • Posts 6,552
    It is far better to return a dataset. Just pass the dataset up from your data layer.
    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Error Meassage

    04-22-2007, 2:14 PM
    • Loading...
    • semsem0
    • Joined on 12-26-2006, 8:28 PM
    • Egypt
    • Posts 136

    thanx but can you also tell me waht is the wrong wiht this

    as iwant to pass the datarow only when i want to update

    do u get what i mean.

    here idon't need to pass the entire dataset

    Hope beSt ThIng Be ArouNd You
  • Re: Error Meassage

    04-22-2007, 3:11 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 8:34 AM
    • England
    • Posts 6,552
    Just create your update stored procedure, passing in the record Id and the fields to update not a datarow. Remember you frequently need to update only a subset of the rows.
    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter