Hi,
I am building class for my project ,but yhe problem i do not get the proper answer
here is the code

[System.ComponentModel.DesignerCategoryAttribute("code")]
public class Buying : System.Data.DataSet
{

    private ContractDataTable tableContract;

    private BuyerDataTable tableBuyer;

    //    private SellerDataTable tableSeller;

    public Buying()
    {
        this.InitClass();
        //
        // TODO: Add constructor logic here
        //
    }
    [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
    public ContractDataTable Contracts_tbl
    {
        get
        {
            return this.tableContract;
        }
    }

    [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
    public BuyerDataTable Buyers_TBL
    {
        get
        {
            return this.tableBuyer;
        }
    }

    /*[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
    public SellerDataTable Sellers_TBL
    {
        get
        {
            return this.tableSeller;
        }
    }*/
    private void InitClass()
    {
        this.DataSetName = "CatalogDS";
        this.Namespace = "http://tempuri.org/XMLSchema.xsd";
        this.tableContract = new ContractDataTable();
        this.Tables.Add(this.tableContract);
        this.tableBuyer = new BuyerDataTable();
        this.Tables.Add(this.tableBuyer);
        /* this.tableSeller = new SellerDataTable();
         this.Tables.Add(this.tableSeller);*/


    }

    public delegate void Contracts_tblRowChangeEventHandler(object sender, Contracts_tblRowChangeEvent e);

    public delegate void Buyers_TBLRowChangeEventHandler(object sender, Buyers_TBLRowChangeEvent e);

    // public delegate void Sellers_TBLRowChangeEventHandler(object sender, Sellers_TBLtRowChangeEvent e);

    public class ContractDataTable : DataTable, System.Collections.IEnumerable
    {

        private DataColumn columnContractID;
        private DataColumn columnId;
        private DataColumn columnGovernorate_ID;
        private DataColumn columnDirectorate;
        private DataColumn columnVillage;
        private DataColumn columnBlock;
        private DataColumn columnSector;
        private DataColumn columnLand;
        private DataColumn columnFraction;
        private DataColumn columnDate;
        private DataColumn columnBooth;
        private DataColumn columnPrice;
        private DataColumn columnRegion;
        private DataColumn columnBuyer;
        private DataColumn columnSeller;
        internal ContractDataTable()
            :
                    base("Contracts_tbl")
        {
            this.InitClass();
        }

        public int Count
        {
            get
            {
                return this.Rows.Count;
            }
        }

        internal DataColumn ContractIDColumn
        {
            get
            {
                return this.columnContractID;
            }
        }

        internal DataColumn Idcolumn
        {
            get
            {
                return this.columnId;
            }
        }

        internal DataColumn Governorate_IDcolumn
        {
            get
            {
                return this.columnGovernorate_ID;
            }
        }

        internal DataColumn DirectorateColumn
        {
            get
            {
                return this.columnDirectorate;
            }
        }


        internal DataColumn VillageColumn
        {
            get
            {
                return this.columnVillage;
            }
        }
        internal DataColumn BlockColumn
        {
            get
            {
                return this.columnBlock;
            }
        }
        internal DataColumn SectorColumn
        {
            get
            {
                return this.columnSector;
            }
        }
        internal DataColumn LandColumn
        {
            get
            {
                return this.columnLand;
            }
        }
        internal DataColumn FractionColumn
        {
            get
            {
                return this.columnFraction;
            }
        }

        internal DataColumn DateColumn
        {
            get
            {
                return this.columnDate;
            }
        }
        internal DataColumn BoothColumn
        {
            get
            {
                return this.columnBooth;
            }
        }
        internal DataColumn PriceColumn
        {
            get
            {
                return this.columnPrice;
            }
        }
        internal DataColumn RegionColumn
        {
            get
            {
                return this.columnRegion;
            }
        }
        internal DataColumn BuyerColumn
        {
            get
            {
                return this.columnBuyer;
            }
        }
        internal DataColumn SellerColumn
        {
            get
            {
                return this.columnSeller;
            }
        }

        public Contracts_tblRow this[int index]
        {
            get
            {
                return ((Contracts_tblRow)(this.Rows[index]));
            }
        }

        public event Contracts_tblRowChangeEventHandler Contracts_tblRowChanged;

        public event Contracts_tblRowChangeEventHandler Contracts_tblRowChanging;

        public event Contracts_tblRowChangeEventHandler Contracts_tblRowDeleted;

        public event Contracts_tblRowChangeEventHandler Contracts_tblRowDeleting;

        public void Add(Contracts_tblRow row)
        {
            this.Rows.Add(row);
        }
        public Contracts_tblRow AddContractRow(string cotract_id, string id, System.Guid Governorate_ID, string Directorate_ID, string Village_ID, string Block_ID, string Sector_ID, string Land_ID,
          string fraction_no, string review_date, string booth_no,
            string price, string region_no, string Buyers_no, string Seller_no)
        {
            Contracts_tblRow rowContracts_tblRow = ((Contracts_tblRow)(this.NewRow()));
            rowContracts_tblRow.ItemArray = new Object[] {cotract_id,
                       id,Governorate_ID, Directorate_ID,Village_ID,Block_ID,
           Sector_ID ,Land_ID ,fraction_no , review_date, booth_no,
            price,region_no, Buyers_no,      Seller_no};
            this.Rows.Add(rowContracts_tblRow);
            return rowContracts_tblRow;

        }

        public Contracts_tblRow FindBycontract_id(string cotract_id)
        {
            return ((Contracts_tblRow)(this.Rows.Find(new Object[] { cotract_id })));
        }

        public System.Collections.IEnumerator GetEnumerator()
        {
            return this.Rows.GetEnumerator();
        }

        private void InitClass()
        {
            this.columnContractID = new DataColumn("cotract_id", typeof(string), "", System.Data.MappingType.Element);
            //  this.columnContractID.AllowDBNull = false;
            //  this.columnContractID.Unique = true;
            this.Columns.Add(this.columnContractID);
            this.columnId = new DataColumn("id", typeof(string), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnId);
            this.columnGovernorate_ID = new DataColumn("Governorate_ID", typeof(string), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnGovernorate_ID);
            this.columnDirectorate = new DataColumn("Directorate_ID", typeof(string), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnDirectorate);
            this.columnVillage = new DataColumn("Village_ID", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnVillage);
            this.columnBlock = new DataColumn("Block_ID", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnBlock);
            this.columnSector = new DataColumn("Sector_ID", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnSector);
            this.columnLand = new DataColumn("Land_ID", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnLand);
            this.columnFraction = new DataColumn(" fraction_no", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnFraction);
            this.columnDate = new DataColumn("review_date", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnDate);
            this.columnBooth = new DataColumn("booth_no", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnBooth);
            this.columnPrice = new DataColumn("price", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnPrice);
            this.columnRegion = new DataColumn("region_no", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnRegion);
            this.columnBuyer = new DataColumn("Buyers_no", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnBuyer);

            this.columnSeller = new DataColumn("Seller_no", typeof(short), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnSeller);


            //this.PrimaryKey = new DataColumn[] { this.columnContractID,this.columnId };
        }

        public Contracts_tblRow NewContracts_tblRow()
        {
            return ((Contracts_tblRow)(this.NewRow()));
        }

        protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
        {
            // We need to ensure that all Rows in the tabled are typed rows.
            // Table calls newRow whenever it needs to create a row.
            // So the following conditions are covered by Row newRow(Record record)
            // * Cursor calls table.addRecord(record) 
            // * table.addRow(object[] values) calls newRow(record)    
            return new Contracts_tblRow(builder);
        }

        protected override System.Type GetRowType()
        {
            return typeof(Contracts_tblRow);
        }

        protected override void OnRowChanged(DataRowChangeEventArgs e)
        {
            base.OnRowChanged(e);
            if ((this.Contracts_tblRowChanged != null))
            {
                this.Contracts_tblRowChanged(this, new Contracts_tblRowChangeEvent(((Contracts_tblRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowChanging(DataRowChangeEventArgs e)
        {
            base.OnRowChanging(e);
            if ((this.Contracts_tblRowChanging != null))
            {
                this.Contracts_tblRowChanging(this, new Contracts_tblRowChangeEvent(((Contracts_tblRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowDeleted(DataRowChangeEventArgs e)
        {
            base.OnRowDeleted(e);
            if ((this.Contracts_tblRowDeleted != null))
            {
                this.Contracts_tblRowDeleted(this, new Contracts_tblRowChangeEvent(((Contracts_tblRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowDeleting(DataRowChangeEventArgs e)
        {
            base.OnRowDeleting(e);
            if ((this.Contracts_tblRowDeleting != null))
            {
                this.Contracts_tblRowDeleting(this, new Contracts_tblRowChangeEvent(((Contracts_tblRow)(e.Row)), e.Action));
            }
        }

        public void RemoveContracts_tblRow(Contracts_tblRow row)
        {
            this.Rows.Remove(row);
        }
    }//ContractDataTable tableContract

    public class Contracts_tblRow : DataRow
    {

        private ContractDataTable tableContract;

        internal Contracts_tblRow(DataRowBuilder rb)
            :
                base(rb)
        {
            this.tableContract = ((ContractDataTable)(this.Table));
        }

        public System.Guid cotract_id
        {
            get
            {
                return ((System.Guid)(this[this.tableContract.ContractIDColumn]));
            }
            set
            {
                this[this.tableContract.ContractIDColumn] = value;
            }
        }

        public string id
        {
            // private DataColumn columnSeller;*/
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.Idcolumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.Idcolumn] = value;
            }
        }

        public System.Guid Governorate_ID
        {
            get
            {
                try
                {
                    return ((System.Guid)(this[this.tableContract.Governorate_IDcolumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.Governorate_IDcolumn] = value;
            }
        }

        public string Directorate_ID
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.DirectorateColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.DirectorateColumn] = value;
            }
        }
        public string Village_ID
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.VillageColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.VillageColumn] = value;
            }
        }
        public string Block_ID
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.BlockColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.BlockColumn] = value;
            }
        }
        public string Sector_ID
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.SectorColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.SectorColumn] = value;
            }
        }
        public string Land_ID
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.LandColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.LandColumn] = value;
            }
        }
        public string fraction_no
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.FractionColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.FractionColumn] = value;
            }
        }

        public string review_date
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.DateColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.DateColumn] = value;
            }
        }
        public string booth_no
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.BoothColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.BoothColumn] = value;
            }
        }
        public string price
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.PriceColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.PriceColumn] = value;
            }
        }
        public string region_no
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.RegionColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.RegionColumn] = value;
            }
        }
        public string Buyers_no
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.BuyerColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.BuyerColumn] = value;
            }
        }
        public string Seller_no
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableContract.SellerColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableContract.SellerColumn] = value;
            }
        }




    }

    public class Contracts_tblRowChangeEvent : EventArgs
    {

        private Contracts_tblRow eventRow;

        private System.Data.DataRowAction eventAction;

        public Contracts_tblRowChangeEvent(Contracts_tblRow row, DataRowAction action)
        {
            this.eventRow = row;
            this.eventAction = action;
        }

        public Contracts_tblRow Row
        {
            get
            {
                return this.eventRow;
            }
        }

        public DataRowAction Action
        {
            get
            {
                return this.eventAction;
            }
        }

    }

    public class BuyerDataTable : DataTable, System.Collections.IEnumerable
    {

        private DataColumn columnNational;

        private DataColumn columnID;

        private DataColumn columnFraction;

        internal BuyerDataTable()
            :
                base("Buyers_TBL")
        {
            this.InitClass();
        }

        public int Count
        {
            get
            {
                return this.Rows.Count;
            }
        }

        internal DataColumn NationalColumn
        {
            get
            {
                return this.columnNational;
            }
        }

        internal DataColumn IDColumn
        {
            get
            {
                return this.columnID;
            }
        }

        internal DataColumn FractionColumn
        {
            get
            {
                return this.columnFraction;
            }
        }
        public Buyers_TBLRow this[int index]
        {
            get
            {
                return ((Buyers_TBLRow)(this.Rows[index]));
            }
        }

        public event Buyers_TBLRowChangeEventHandler Buyers_TBLRowChanged;

        public event Buyers_TBLRowChangeEventHandler Buyers_TBLRowChanging;

        public event Buyers_TBLRowChangeEventHandler Buyers_TBLRowDeleted;

        public event Buyers_TBLRowChangeEventHandler Buyers_TBLRowDeleting;

        public void Buyers_TBLRow(Buyers_TBLRow row)
        {
            this.Rows.Add(row);
        }
        public Buyers_TBLRow AddBuyers_TBLRow(string national_no,string  contract_id,string fraction_sold)
        {
            Buyers_TBLRow rowBuyers_TBLRow  = ((Buyers_TBLRow)(this.NewRow()));
            rowBuyers_TBLRow.ItemArray = new Object[] { national_no,
                       contract_id,  fraction_sold };
            this.Rows.Add(rowBuyers_TBLRow);
            return (rowBuyers_TBLRow);
        }

        public Buyers_TBLRow FindByID(string national_no)
        {
            return ((Buyers_TBLRow)(this.Rows.Find(new Object[] { national_no })));
        }

        public System.Collections.IEnumerator GetEnumerator()
        {
            return this.Rows.GetEnumerator();
        }

        private void InitClass()
        {

        //private DataColumn columnID;

//        private DataColumn columnFraction;

            this.columnNational = new DataColumn("national_no", typeof(string), "", System.Data.MappingType.Element);
            //this.columnNational.AutoIncrement = true;
          //  this.columnNational.AllowDBNull = false;
           // this.columnID.ReadOnly = true;
          //  this.columnNational.Unique = true;
            this.Columns.Add(this.columnNational);
            this.columnID = new DataColumn("contract_id", typeof(string), "", System.Data.MappingType.Element);
            this.Columns.Add(this.columnID);
            this.columnFraction = new DataColumn("fraction_sold ", typeof(string), "", System.Data.MappingType.Element);
            //this.columnFraction.AllowDBNull = false;
            this.Columns.Add(this.columnFraction);
          //  this.PrimaryKey = new DataColumn[] { this.columnID };
        }

        public Buyers_TBLRow NewBuyers_TBLRow()
        {
            return ((Buyers_TBLRow)(this.NewRow()));
        }

        protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
        {
            // We need to ensure that all Rows in the tabled are typed rows.
            // Table calls newRow whenever it needs to create a row.
            // So the following conditions are covered by Row newRow(Record record)
            // * Cursor calls table.addRecord(record) 
            // * table.addRow(object[] values) calls newRow(record)    
            return new Buyers_TBLRow(builder);
        }

        protected override System.Type GetRowType()
        {
            return typeof(Buyers_TBLRow);
        }

        protected override void OnRowChanged(DataRowChangeEventArgs e)
        {
            base.OnRowChanged(e);
            if ((this.Buyers_TBLRowChanged != null))
            {
                this.Buyers_TBLRowChanged(this, new Buyers_TBLRowChangeEvent(((Buyers_TBLRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowChanging(DataRowChangeEventArgs e)
        {
            base.OnRowChanging(e);
            if ((this.Buyers_TBLRowChanging != null))
            {
                this.Buyers_TBLRowChanging(this, new Buyers_TBLRowChangeEvent(((Buyers_TBLRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowDeleted(DataRowChangeEventArgs e)
        {
            base.OnRowDeleted(e);
            if ((this.Buyers_TBLRowDeleted != null))
            {
                this.Buyers_TBLRowDeleted(this, new Buyers_TBLRowChangeEvent(((Buyers_TBLRow)(e.Row)), e.Action));
            }
        }

        protected override void OnRowDeleting(DataRowChangeEventArgs e)
        {
            base.OnRowDeleting(e);
            if ((this.Buyers_TBLRowDeleting != null))
            {
                this.Buyers_TBLRowDeleting(this, new Buyers_TBLRowChangeEvent(((Buyers_TBLRow)(e.Row)), e.Action));
            }
        }

        public void RemoveBuyers_TBLRow(Buyers_TBLRow row)
        {
            this.Rows.Remove(row);
        }
    }


    public class Buyers_TBLRow : DataRow
    {

        private BuyerDataTable tableBuyer;

        internal Buyers_TBLRow(DataRowBuilder rb)
            :
                base(rb)
        {
            this.tableBuyer = ((BuyerDataTable)(this.Table));
        }

        public string national_no
        {
            get
            {
                return ((string)(this[this.tableBuyer.NationalColumn]));
            }
            set
            {
                this[this.tableBuyer.NationalColumn] = value;
            }
        }

        public string contract_id
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableBuyer.IDColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                }
            }
            set
            {
                this[this.tableBuyer.IDColumn] = value;
            }
        }

        public string fraction_sold
        {
            get
            {
                return ((string)(this[this.tableBuyer.FractionColumn]));
            }
            set
            {
                this[this.tableBuyer.FractionColumn] = value;
            }
        }



    }
    public class Buyers_TBLRowChangeEvent : EventArgs
    {

        private Buyers_TBLRow eventRow;

        private System.Data.DataRowAction eventAction;

        public Buyers_TBLRowChangeEvent(Buyers_TBLRow row, DataRowAction action)
        {
            this.eventRow = row;
            this.eventAction = action;
        }

        public Buyers_TBLRow Row
        {
            get
            {
                return this.eventRow;
            }
        }

        public DataRowAction Action
        {
            get
            {
                return this.eventAction;
            }
        }
    }


}

Edited 3 Years Ago by happygeek: fixed formatting

Hi there,

what problem you are facing in it ?

To make more convenient to read the code.

Actually right now I haven’t read your code, after reading I'll try to come with some help

Edited 3 Years Ago by pyTony: fixed formatting

Hi there,

what problem you are facing in it ?

Actually right now I haven’t read the your code, after reading I'll try to come with some help

when used this class and connect it to database the result was incorrect ,for the Buyers_TBL .
the table is Buyers contains the following fields national_no,contract_id,fraction_sold

Edited 3 Years Ago by pyTony: fixed formatting

This article has been dead for over six months. Start a new discussion instead.