Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i've encountered some problems with my custom datatable, after make some changes (adding one single row)) i'm trying to get GetChanges(), but it returns all records (1k+). Whats wrong with it?

C#
public class ControlPointsDataTable: BaseDataTable
    {
        public ControlPointsDataTable()
        {
            TableName = "ControlPoints";
            TableDescription = "Contains system control points";

        DataColumn dataColumnID = new DataColumn("ID", typeof(System.Int64));
        dataColumnID.Caption = "ID";
        dataColumnID.AllowDBNull  = false;
        dataColumnID.DefaultValue = -1;
        Columns.Add(dataColumnID);

        DataColumn dataColumnName = new DataColumn("Name", typeof(System.Int64));
        dataColumnName.Caption = "CP Name";
        dataColumnName.AllowDBNull  = false;
        dataColumnName.DefaultValue = -1;
        Columns.Add(dataColumnName);

        }

        protected override Type GetRowType()
        {
          return typeof(ControlPointsRow);
        }

        protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
        {
          return new ControlPointsRow(builder);
        }

        public ControlPointsRow this[int idx]
        {
          get { return (ControlPointsRow)Rows[idx]; }
        }

        public void Add(ControlPointsRow row)
        {
          Rows.Add(row);
        }

        public void Remove(ControlPointsRow row)
        {
          Rows.Remove(row);
        }

        public ControlPointsRow GetNewRow()
        {
          ControlPointsRow row = (ControlPointsRow)NewRow();

          return row;
        }

        public class ControlPointsRow : DataRow
        {

        [DataMember]
        public System.Int64 ID 
        {
          get {return (System.Int64)base["ID"];}
          set {base["ID"]=value;}
        }

        [DataMember]
        public System.Int64 Name 
        {
          get {return (System.Int64)base["Name"];}
          set {base["Name"]=value;}
        }


          internal ControlPointsRow(DataRowBuilder builder) : base(builder) {} 
        }
    }


My custom base DataTable class:
C#
[ServiceContract(Namespace = Constants.NAMESPACE)]
public class BaseDataTable : DataTable
{
    public string TableDescription { get; set; }
}
Posted
Updated 13-Aug-14 4:28am
v2
Comments
Herman<T>.Instance 13-Aug-14 10:44am    
Did you debug your code?

1 solution

Once you load the Datatable.

You will have to say

Datatable.AcceptChanges() for the initial commit

Then when you run getchanges after insert , it should return the new row inserted
 
Share this answer
 
Comments
Member 10966414 14-Aug-14 9:06am    
made this, but strange things still happen...
let's say, when i call _records.GetChanges(DataRowState.Modified).Rows.Count();
returns 1, it's ok.
But when i'm trying to make something like this:
var dt = _records.GetChanges(DataRowState.Modified);
dt variablie is always NULL.
member33 14-Aug-14 9:07am    
you might have to do

var dt = _records.GetChanges(DataRowState.Modified).Rows
Member 10966414 18-Aug-14 4:18am    
it works, thank you!

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