Update DataSet

S

samoore33

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(filterExp,
sortExp)

For count = 0 To myTable.Rows.Count
Dim changeDate As DateTime =
Convert.ToDateTime(myData.Tables("Information").Rows(count).Item(count
+ 1))

changeDate = changeDate.AddYears(1).ToShortDateString()

myData.Tables("Information").Rows(count).Item(count +
1).Add(changeDate).
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
 
C

Cor Ligthert [MVP]

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.rows
row("YourDateTimeColumn") = row("YourDateTimeColumn").AddYears(1)
next
///

http://msdn2.microsoft.com/en-us/library/system.datetime.addyears.aspx

I hope this helps,

Cor
 
S

samoore33

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.ReadXml("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").AddYears(1)
Next
 
C

Cor Ligthert [MVP]

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).ToShortString ' or whatever
Next

Can you try that one,

I hope this helps,

Cor
 
S

samoore33

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
 
C

Cor Ligthert [MVP]

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("Date", 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).ToString("dd-MM-yyyy")
' or whatever
Next
MessageBox.Show(dt.Rows(11)("Date").ToString) 'shows 01-12-2006
///
I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top