Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I am trying to do is to use a variable in vb code to update a xml configfile's <LastRunDateTime>2018-03-30T00:00:00</LastRunDateTime> every time the program runs the strSQL.
I want to only update the LastRunDateTime node text

Here is the config xml file:
XML
<?xml version="1.0" encoding="UTF-8"?>
<DocGetAuditReport.Config>
	<LastRunDateTime>2018-03-30T00:00:00</LastRunDateTime>
</DocGetAuditReport.Config>


What I have tried:

VB
 Public Class MyClassR
    Shared Sub main()
        Dim strLastRunDateTime As String
		Dim dtmCurrentDateTime As Date = Now
        Dim objXmlConfigDoc As XmlDocument
        Dim strSQL As String
        Dim objXmlResultDoc As XmlDocument
        Dim objXMLNode As XmlNode
        Try
           'Load DocGetAuditReport file and get last run date time dtmLastRunDateTime
            'Dim objXmlTaskConfigDoc As XmlDocument = Msc.Integration.Utility.Library.v4.ProgramExecution.GetConfigFile("Msc.Integration.MessageWarehouse.Task.v4.DocGetAuditReport.Config.xml")
			 Dim objXmlTaskConfigDoc As XmlDocument = GetConfigFile("Config.xml")
            strLastRunDateTime = objXmlTaskConfigDoc.DocumentElement.SelectSingleNode("LastRunDateTime").InnerText.Replace("T", " ")
            strSQL = GetSql(strLastRunDateTime, dtmCurrentDateTime)

            'THIS IS WHERE I would like to use variable dtmCurrentDateTime to update objXmlConfigDoc xml file with current date instead of what it has now <LastRunDateTime>2018-03-30T00:00:00</LastRunDateTime>
            'objXmlConfigDoc = GetConfigFile("Config.xml")
    End Sub
    Private Shared Function GetSql(ByVal astrLastRunDateTime As String, ByVal adtmCurrentDateTime As Date) As String
        Dim strSQL As String
        strSQL ="SELECT Something, ProcessDateTime AS 'RequestDateTime'," + vbCrLf +
        "FROM TableName" + vbCrLf +
       "And (ProcessDateTime > CONVERT(DATETIME, '" + astrLastRunDateTime + "', 102))" + vbCrLf +
     "AND (ProcessDateTime <= CONVERT(DATETIME, '" + adtmCurrentDateTime.ToString + "', 102))" + vbCrLf +
       Return strSQL
    End Function
End Class
Posted
Updated 5-Apr-18 20:36pm
v4
Comments
Maciej Los 6-Apr-18 2:10am    
What .NET framework: 2, 3, 3.5, ...?

1 solution

You're on the right track! Small improvement:
VB.NET
Dim xNode As XmlNode = objXmlTaskConfigDoc.DocumentElement.SelectSingleNode("DocGetAuditReport.Config/LastRunDateTime")
xNode.InnetText = DateTime.Today.ToString("yyyy-MM-dd")
'save xml here!
 
Share this answer
 
Comments
Member 11403304 6-Apr-18 8:29am    
How to I make the date to look like this 2018-03-30T00:00:00
Maciej Los 6-Apr-18 8:39am    
Like this:
xNode.InnetText = DateTime.Today.ToString("yyyy-MM-ddTHH:mm:ss")

In case you'd like to store time part:
xNode.InnetText = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")
Member 11403304 6-Apr-18 8:48am    
Awesome. It is working! Thank you Maciej Los
Maciej Los 6-Apr-18 8:55am    
You're very welcome.

Cheers,
Maciej

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