0

I have row value in datagridview, I want to write some value in xml but I cant execute the for loop inside xml

Public Sub WriteXML()
    Dim uTime As Double

    uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
    Dim formattedValue As Double = CDbl(uTime)
    uTime = formattedValue.ToString("N3").Replace(".", "")

    Dim document As XDocument = <?xml version="1.0" encoding="UTF-8"?>
                                <XmlStatus name=<%= uTime %>>
                                <versionInfo>
                                <Parameters name="Param">
                                <list>
                                <%= For i = 0 To Form1.DataGridView1.RowCount - 1
                                    <mydate uniqueId=<%= uTime %>>
                                        <Parameter name="common">
                                            <Param name="Name" value="test1"/>
                                        </Parameter>
                                    </mydate>
                                Next  %>
                                </list>
                                </Parameters>
                                </versionInfo>
                                </XmlStatus>

I tried it another way

Public Function SlicesWriter()
    Dim test As String
    For i = 0 To Form1.DataGridView1.RowCount - 1
        If Not (Form1.DataGridView1.Rows(i).Cells(2).Value.ToString = 0) Then
            test = "<mydate uniqueId=" & uTime & ">"
            test = "<Parameter name=common>"
        End If
    Next

    Return test

End Function

the problem with that function is I cannot scape the <> when the xml file was save the value on that line is

&lt;mydate uniqueId=1748079638388&gt;

thanks in advance!

6
  • stackoverflow.com/a/72765981/14171304 Commented May 24 at 14:55
  • The following may be of interest: stackoverflow.com/a/73640395/10024425 and stackoverflow.com/a/68513150/10024425 Commented May 24 at 18:51
  • that is not helpfull, What I need is for loop, because the number line on xml depend on the number of row in datagridview. eg. I have 5 rows with different value. I need to create an xml 5 times with same value on datagridview. Commented May 24 at 23:00
  • What you've provided is nonsensical. Did you use AI to write it? I recommend that you describe what you're trying to accomplish rather than how you're attempting to accomplish it. While it appears that you've been a member of SO for > 9 yrs, you may benefit from a refresher on How do I ask a good question? and perhaps pseudo-code Commented May 25 at 3:52
  • thanks. I already figure it out I generate the xml using for loop. the problem is it give one data even in for loop. because the return function only give one data. I tried sub but cannot accept inside the xml. Commented May 25 at 11:15

1 Answer 1

1

Not sure what you are trying to do but this is how to do a 'for' loop based on a count,

        Dim uTime As Double

        uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds

        Dim document As XElement
        document = <data>
                       <versionInfo>
                           <Parameters name="Param">
                               <list>
                                   <%= From x In Enumerable.Range(0, DataGridView1.RowCount - 1)
                                       Select
                                           <mydate uniqueId=<%= uTime %> x=<%= x %>>
                                               <Paramater name="common">
                                                   <Param name="Name" value="test1"/>
                                               </Paramater>
                                           </mydate>
                                   %>
                               </list>
                           </Parameters>
                       </versionInfo>
                   </data>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.