Comparing Dataset Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franck

    #1

    Comparing Dataset Question

    how come unchanged always true even if data changed

    This code come from my saving button:

    =============== =============== ==============
    DataSet ds1 = new DataSet();
    DataSet ds2 = new DataSet();
    DataSet ds3 = new DataSet();

    //Static Dataset which contain values when my form load
    ds1.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
    //this datatable contain the value of all controls when saving
    ds2.Tables.Add( dt.Copy());

    ds3.Merge(ds1);
    ds3.AcceptChang es();
    //now ds1 supposed to be the reference
    ds3.Merge(ds2);
    //ds2 contain the same structure as ds1 but may have different values

    //this test should tell me is ds2 changed ds1 but it does always
    return true
    if (ds3.HasChanges (DataRowState.U nchanged) == false)
    {
    for (int y = 0; y <= 31; y++)
    {
    //filling data with datarows of dt
    ModelSelectionG lobal.dsModelSe lection.Tables["C"].Rows[0]
    [y] = dr[y];
    }
    }
    =============== =============== =============== ==========

    what im doing wrong here ?

  • =?Utf-8?B?QWRhbSBCaWVnYW5za2k=?=

    #2
    RE: Comparing Dataset Question

    Hi Franck,
    if (ds3.HasChanges (DataRowState.U nchanged) == false)
    I think instead you should try:
    if (ds3.HasChanges () == false)

    and you can actually skip the comparing to 'false':
    if (!ds3.HasChange s())


    Hope this helps :)
    --
    _____________
    Adam Bieganski
    Every day's adventures in .NET Framework



    "Franck" wrote:
    how come unchanged always true even if data changed
    >
    This code come from my saving button:
    >
    =============== =============== ==============
    DataSet ds1 = new DataSet();
    DataSet ds2 = new DataSet();
    DataSet ds3 = new DataSet();
    >
    //Static Dataset which contain values when my form load
    ds1.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
    //this datatable contain the value of all controls when saving
    ds2.Tables.Add( dt.Copy());
    >
    ds3.Merge(ds1);
    ds3.AcceptChang es();
    //now ds1 supposed to be the reference
    ds3.Merge(ds2);
    //ds2 contain the same structure as ds1 but may have different values
    >
    //this test should tell me is ds2 changed ds1 but it does always
    return true
    if (ds3.HasChanges (DataRowState.U nchanged) == false)
    {
    for (int y = 0; y <= 31; y++)
    {
    //filling data with datarows of dt
    ModelSelectionG lobal.dsModelSe lection.Tables["C"].Rows[0]
    [y] = dr[y];
    }
    }
    =============== =============== =============== ==========
    >
    what im doing wrong here ?
    >
    >

    Comment

    • Franck

      #3
      Re: Comparing Dataset Question

      On Oct 19, 10:21 am, Adam Bieganski <abieganski(at) gmail.comwrote:
      Hi Franck,
      >
      if (ds3.HasChanges (DataRowState.U nchanged) == false)
      >
      I think instead you should try:
      if (ds3.HasChanges () == false)
      >
      and you can actually skip the comparing to 'false':
      if (!ds3.HasChange s())
      >
      Hope this helps :)
      --
      _____________
      Adam Bieganskihttp://godevelop.blogs pot.com
      >
      "Franck" wrote:
      how come unchanged always true even if data changed
      >
      This code come from my saving button:
      >
      =============== =============== ==============
      DataSet ds1 = new DataSet();
      DataSet ds2 = new DataSet();
      DataSet ds3 = new DataSet();
      >
      //Static Dataset which contain values when my form load
      ds1.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
      //this datatable contain the value of all controls when saving
      ds2.Tables.Add( dt.Copy());
      >
      ds3.Merge(ds1);
      ds3.AcceptChang es();
      //now ds1 supposed to be the reference
      ds3.Merge(ds2);
      //ds2 contain the same structure as ds1 but may have different values
      >
      //this test should tell me is ds2 changed ds1 but it does always
      return true
      if (ds3.HasChanges (DataRowState.U nchanged) == false)
      {
      for (int y = 0; y <= 31; y++)
      {
      //filling data with datarows of dt
      ModelSelectionG lobal.dsModelSe lection.Tables["C"].Rows[0]
      [y] = dr[y];
      }
      }
      =============== =============== =============== ==========
      >
      what im doing wrong here ?
      This works but i have a second issue.
      when i merge ds2 inside ds3 i thought it would overwrite ds1 thats
      already there but it's not. even if the tables have the same name it
      does not replace but create another table, so in my ds3 the ds1 is :
      ds3.table[0] and ds2 is ds3.table[1]. that's why haschanges say it
      havent been changed.

      Comment

      • =?Utf-8?B?QWRhbSBCaWVnYW5za2k=?=

        #4
        Re: Comparing Dataset Question

        "Franck" wrote:
        On Oct 19, 10:21 am, Adam Bieganski <abieganski(at) gmail.comwrote:
        Hi Franck,
        if (ds3.HasChanges (DataRowState.U nchanged) == false)
        I think instead you should try:
        if (ds3.HasChanges () == false)

        and you can actually skip the comparing to 'false':
        if (!ds3.HasChange s())

        Hope this helps :)
        --
        _____________
        Adam Bieganskihttp://godevelop.blogs pot.com

        "Franck" wrote:
        how come unchanged always true even if data changed
        This code come from my saving button:
        =============== =============== ==============
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        DataSet ds3 = new DataSet();
        //Static Dataset which contain values when my form load
        ds1.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
        //this datatable contain the value of all controls when saving
        ds2.Tables.Add( dt.Copy());
        ds3.Merge(ds1);
        ds3.AcceptChang es();
        //now ds1 supposed to be the reference
        ds3.Merge(ds2);
        //ds2 contain the same structure as ds1 but may have different values
        //this test should tell me is ds2 changed ds1 but it does always
        return true
        if (ds3.HasChanges (DataRowState.U nchanged) == false)
        {
        for (int y = 0; y <= 31; y++)
        {
        //filling data with datarows of dt
        ModelSelectionG lobal.dsModelSe lection.Tables["C"].Rows[0]
        [y] = dr[y];
        }
        }
        =============== =============== =============== ==========
        what im doing wrong here ?
        >
        This works but i have a second issue.
        when i merge ds2 inside ds3 i thought it would overwrite ds1 thats
        already there but it's not. even if the tables have the same name it
        does not replace but create another table, so in my ds3 the ds1 is :
        ds3.table[0] and ds2 is ds3.table[1]. that's why haschanges say it
        havent been changed.
        I think you can get rid of the first 2 datasets completely:

        ds3.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
        ds3.AcceptChang es();
        ds3.Merge(dt.Co py());

        If this doesn't help - try to explicitly set the names of the tables
        returned by the Copy() methods:

        DataTable dt1 = ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy();
        dt1.TableName = "Table1";
        ds3.Tables.Add( dt1);
        ds3.AcceptChang es();
        dt1 = dt.Copy();
        dt1.TableName = "Table1";
        ds3.Merge(dt1);

        Cheers,
        --
        _____________
        Adam Bieganski
        Every day's adventures in .NET Framework


        Comment

        • Franck

          #5
          Re: Comparing Dataset Question

          On Oct 19, 12:21 pm, Adam Bieganski <abieganski(at) gmail.comwrote:
          "Franck" wrote:
          On Oct 19, 10:21 am, Adam Bieganski <abieganski(at) gmail.comwrote:
          Hi Franck,
          >
          if (ds3.HasChanges (DataRowState.U nchanged) == false)
          >
          I think instead you should try:
          if (ds3.HasChanges () == false)
          >
          and you can actually skip the comparing to 'false':
          if (!ds3.HasChange s())
          >
          Hope this helps :)
          --
          _____________
          Adam Bieganskihttp://godevelop.blogs pot.com
          >
          "Franck" wrote:
          how come unchanged always true even if data changed
          >
          This code come from my saving button:
          >
          =============== =============== ==============
          DataSet ds1 = new DataSet();
          DataSet ds2 = new DataSet();
          DataSet ds3 = new DataSet();
          >
          //Static Dataset which contain values when my form load
          ds1.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
          //this datatable contain the value of all controls when saving
          ds2.Tables.Add( dt.Copy());
          >
          ds3.Merge(ds1);
          ds3.AcceptChang es();
          //now ds1 supposed to be the reference
          ds3.Merge(ds2);
          //ds2 contain the same structure as ds1 but may have different values
          >
          //this test should tell me is ds2 changed ds1 but it does always
          return true
          if (ds3.HasChanges (DataRowState.U nchanged) == false)
          {
          for (int y = 0; y <= 31; y++)
          {
          //filling data with datarows of dt
          ModelSelectionG lobal.dsModelSe lection.Tables["C"].Rows[0]
          [y] = dr[y];
          }
          }
          =============== =============== =============== ==========
          >
          what im doing wrong here ?
          >
          This works but i have a second issue.
          when i merge ds2 inside ds3 i thought it would overwrite ds1 thats
          already there but it's not. even if the tables have the same name it
          does not replace but create another table, so in my ds3 the ds1 is :
          ds3.table[0] and ds2 is ds3.table[1]. that's why haschanges say it
          havent been changed.
          >
          I think you can get rid of the first 2 datasets completely:
          >
          ds3.Tables.Add( ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy());
          ds3.AcceptChang es();
          ds3.Merge(dt.Co py());
          >
          If this doesn't help - try to explicitly set the names of the tables
          returned by the Copy() methods:
          >
          DataTable dt1 = ModelSelectionG lobal.dsModelSe lection.Tables["C"].Copy();
          dt1.TableName = "Table1";
          ds3.Tables.Add( dt1);
          ds3.AcceptChang es();
          dt1 = dt.Copy();
          dt1.TableName = "Table1";
          ds3.Merge(dt1);
          >
          Cheers,
          --
          _____________
          Adam Bieganskihttp://godevelop.blogs pot.com
          nothing works,

          gonna do if statement with and compare all my fields one by one this
          im sure it works.

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: Comparing Dataset Question

            Frank,

            AFAIK does merge not change the rowstates, the merge is merging rows (and
            adding and changing new ones for old ones, however is not affecting the
            fields).

            Cor

            Comment

            Working...