Update DataSet

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

    #1

    Update DataSet

    I have created a xml doc that stores dates. On the first of the year I
    want to upload the xml doc into a dataset and then loop through it
    adding one year to those dates.

    This is what I have attempted.

    myData.ReadXml( "this.xml")
    myTable = myData.Tables(" myInformation")

    myRow = myData.Tables(" myInformation") .Select(filterE xp,
    sortExp)

    For count = 0 To myTable.Rows.Co unt
    Dim changeDate As DateTime =
    Convert.ToDateT ime(myData.Tabl es("Information ").Rows(count). Item(count
    + 1))

    changeDate = changeDate.AddY ears(1).ToShort DateString()

    myData.Tables(" Information").R ows(count).Item (count +
    1).Add(changeDa te).
    I am getting an error on this line, Public member 'Add' on type
    'String' not found.

    Next

    I have tried using ToString() and that does not work either.

    I know there are easier ways of doing this, but just something I am
    messing around with. Any help would be appreciated.

    Scott Moore

  • Cor Ligthert [MVP]

    #2
    Re: Update DataSet

    Samoore33,

    An XML doc and an XML dataset are not direct the same thing.

    A dataset does not contain attributes but only elements. (You can convert
    mostly a XML doc to a dataset).

    Those elements are from the valid Net types. In this case it should it be
    than of the type DateTime.

    If that is as I wrote than it simple.
    \\\
    For each row as datarow in YourDataTable.r ows
    row("YourDateTi meColumn") = row("YourDateTi meColumn").AddY ears(1)
    next
    ///

    http://msdn2.microsoft.com/en-us/lib....addyears.aspx

    I hope this helps,

    Cor

    "samoore33" <samoore33@gmai l.comschreef in bericht
    news:1155660850 .763403.70500@p 79g2000cwp.goog legroups.com...
    >I have created a xml doc that stores dates. On the first of the year I
    want to upload the xml doc into a dataset and then loop through it
    adding one year to those dates.
    >
    This is what I have attempted.
    >
    myData.ReadXml( "this.xml")
    myTable = myData.Tables(" myInformation")
    >
    myRow = myData.Tables(" myInformation") .Select(filterE xp,
    sortExp)
    >
    For count = 0 To myTable.Rows.Co unt
    Dim changeDate As DateTime =
    Convert.ToDateT ime(myData.Tabl es("Information ").Rows(count). Item(count
    + 1))
    >
    changeDate = changeDate.AddY ears(1).ToShort DateString()
    >
    myData.Tables(" Information").R ows(count).Item (count +
    1).Add(changeDa te).
    I am getting an error on this line, Public member 'Add' on type
    'String' not found.
    >
    Next
    >
    I have tried using ToString() and that does not work either.
    >
    I know there are easier ways of doing this, but just something I am
    messing around with. Any help would be appreciated.
    >
    Scott Moore
    >

    Comment

    • samoore33

      #3
      Re: Update DataSet

      Cor,

      I tried that, I get the error of Public member 'AddYears' on type
      'String' not found. I am going to search for the error and see what I
      can find. Below is the code I am using.

      For the xml doc, I am using myDataSet.ReadX ml("myXml.xml" ) to bring
      upload the xml doc into my dataset. Not sure if that makes a
      difference.

      Dim myData As New DataSet("myXML" )
      Dim myTable As DataTable
      Dim r As DataRow
      Dim c As DataColumn

      myData.ReadXml( "myXml.xml" )
      myTable = myData.Tables(" myInfo")

      For Each r In myTable.Rows
      r("Date") = r("Date").AddYe ars(1)
      Next

      Cor Ligthert [MVP] wrote:
      Samoore33,
      >
      An XML doc and an XML dataset are not direct the same thing.
      >
      A dataset does not contain attributes but only elements. (You can convert
      mostly a XML doc to a dataset).
      >
      Those elements are from the valid Net types. In this case it should it be
      than of the type DateTime.
      >
      If that is as I wrote than it simple.
      \\\
      For each row as datarow in YourDataTable.r ows
      row("YourDateTi meColumn") = row("YourDateTi meColumn").AddY ears(1)
      next
      ///
      >
      http://msdn2.microsoft.com/en-us/lib....addyears.aspx
      >
      I hope this helps,
      >
      Cor
      >
      "samoore33" <samoore33@gmai l.comschreef in bericht
      news:1155660850 .763403.70500@p 79g2000cwp.goog legroups.com...
      I have created a xml doc that stores dates. On the first of the year I
      want to upload the xml doc into a dataset and then loop through it
      adding one year to those dates.

      This is what I have attempted.

      myData.ReadXml( "this.xml")
      myTable = myData.Tables(" myInformation")

      myRow = myData.Tables(" myInformation") .Select(filterE xp,
      sortExp)

      For count = 0 To myTable.Rows.Co unt
      Dim changeDate As DateTime =
      Convert.ToDateT ime(myData.Tabl es("Information ").Rows(count). Item(count
      + 1))

      changeDate = changeDate.AddY ears(1).ToShort DateString()

      myData.Tables(" Information").R ows(count).Item (count +
      1).Add(changeDa te).
      I am getting an error on this line, Public member 'Add' on type
      'String' not found.

      Next

      I have tried using ToString() and that does not work either.

      I know there are easier ways of doing this, but just something I am
      messing around with. Any help would be appreciated.

      Scott Moore

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Update DataSet

        Samoore,

        Your date is probably in a string format. However, you can than probably
        still slightly changed use this.

        myData.ReadXml( "myXml.xml" )
        myTable = myData.Tables(" myInfo")
        For Each r In myTable.Rows
        r("Date") = CDate(r("Date") ).AddYears(1).T oShortString ' or whatever
        Next

        Can you try that one,

        I hope this helps,

        Cor



        Comment

        • samoore33

          #5
          Re: Update DataSet

          Cor,

          Same error. I am not even sure if this is possible. This is just
          something I have been messing with, but want to try to get it to work.
          I will keep searching for answers. Not sure what else to do though.

          I know the easy way of doing this is storing things in a Database, but
          figured that was the easy way, so I started messing with the xml into a
          DataSet.

          Samoore

          Cor Ligthert [MVP] wrote:
          Samoore,
          >
          Your date is probably in a string format. However, you can than probably
          still slightly changed use this.
          >
          myData.ReadXml( "myXml.xml" )
          myTable = myData.Tables(" myInfo")
          For Each r In myTable.Rows
          r("Date") = CDate(r("Date") ).AddYears(1).T oShortString ' or whatever
          Next
          >
          Can you try that one,
          >
          I hope this helps,
          >
          Cor

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Update DataSet

            Samoore,

            I made a test it works as a charm (I did only look in your code to that add
            part)

            \\\
            Dim dt As New DataTable
            Dim dc As New DataColumn("Dat e", GetType(System. String))
            dt.Columns.Add( dc)
            For i As Integer = 1 To 12
            dt.LoadDataRow( New Object() {"1-" & i.ToString & "-2005"}, True)
            'my culture uses dd-MM-yyyy
            Next
            For Each r As DataRow In dt.Rows
            r("Date") = CDate(r("Date") ).AddYears(1).T oString("dd-MM-yyyy")
            ' or whatever
            Next
            MessageBox.Show (dt.Rows(11)("D ate").ToString ) 'shows 01-12-2006
            ///
            I hope this helps,

            Cor

            "samoore33" <samoore33@gmai l.comschreef in bericht
            news:1155745877 .394448.293450@ 75g2000cwc.goog legroups.com...
            Cor,
            >
            Same error. I am not even sure if this is possible. This is just
            something I have been messing with, but want to try to get it to work.
            I will keep searching for answers. Not sure what else to do though.
            >
            I know the easy way of doing this is storing things in a Database, but
            figured that was the easy way, so I started messing with the xml into a
            DataSet.
            >
            Samoore
            >
            Cor Ligthert [MVP] wrote:
            >Samoore,
            >>
            >Your date is probably in a string format. However, you can than probably
            >still slightly changed use this.
            >>
            >myData.ReadXml ("myXml.xml" )
            >myTable = myData.Tables(" myInfo")
            > For Each r In myTable.Rows
            > r("Date") = CDate(r("Date") ).AddYears(1).T oShortString ' or
            >whatever
            > Next
            >>
            >Can you try that one,
            >>
            >I hope this helps,
            >>
            >Cor
            >

            Comment

            • samoore33

              #7
              Re: Update DataSet

              Cor,

              Thanks, that worked. I appreciate the help.

              Samoore

              Cor Ligthert [MVP] wrote:
              Samoore,
              >
              I made a test it works as a charm (I did only look in your code to that add
              part)
              >
              \\\
              Dim dt As New DataTable
              Dim dc As New DataColumn("Dat e", GetType(System. String))
              dt.Columns.Add( dc)
              For i As Integer = 1 To 12
              dt.LoadDataRow( New Object() {"1-" & i.ToString & "-2005"}, True)
              'my culture uses dd-MM-yyyy
              Next
              For Each r As DataRow In dt.Rows
              r("Date") = CDate(r("Date") ).AddYears(1).T oString("dd-MM-yyyy")
              ' or whatever
              Next
              MessageBox.Show (dt.Rows(11)("D ate").ToString ) 'shows 01-12-2006
              ///
              I hope this helps,
              >
              Cor
              >
              "samoore33" <samoore33@gmai l.comschreef in bericht
              news:1155745877 .394448.293450@ 75g2000cwc.goog legroups.com...
              Cor,

              Same error. I am not even sure if this is possible. This is just
              something I have been messing with, but want to try to get it to work.
              I will keep searching for answers. Not sure what else to do though.

              I know the easy way of doing this is storing things in a Database, but
              figured that was the easy way, so I started messing with the xml into a
              DataSet.

              Samoore

              Cor Ligthert [MVP] wrote:
              Samoore,
              >
              Your date is probably in a string format. However, you can than probably
              still slightly changed use this.
              >
              myData.ReadXml( "myXml.xml" )
              myTable = myData.Tables(" myInfo")
              For Each r In myTable.Rows
              r("Date") = CDate(r("Date") ).AddYears(1).T oShortString ' or
              whatever
              Next
              >
              Can you try that one,
              >
              I hope this helps,
              >
              Cor

              Comment

              Working...