none
How To Coverte This Query To XML Language? RRS feed

  • Question

  • Hi EveryOne ,

    I want To to Converte this query to Xml :

      Public Function GetDate() As DataTable
            Dim dt As New DataTable
    
            Dim selectStatement As String =
                    <SQL>
                 Select C1, C2,C3
    ,Date1
    ,Date2
    ,Date3
    ,Date4
     From Table WHERE (Date1>=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1<DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))
    </SQL>.Value
    
            Using con = New SqlConnection(ConnectionString)
                Using cmd = New SqlCommand() With
                {
                .Connection = con,
                .CommandText = selectStatement
                }
                    con.Open()
                    dt.Load(cmd.ExecuteReader())
    
                End Using
            End Using
    
            Return dt
    
        End Function

    I Tried To change [( >,<,(,)] by xml characters but it give false resulte:

    WHERE &#40;Date1 &#60;&#61;DATEADD &#40;day, DATEDIFF &#40;day,0,GETDATE &#40;&#41;&#41;,0 &#41;
    AND Date1 &#60;DATEADD &#40; day, DATEDIFF &#40;day,0,GETDATE &#40; &#41; &#41; +1,0 &#41;&#41;

    Thank you ,

    Best regards ,Bajtitou.




    • Edited by Bajtitou Sunday, April 15, 2018 2:08 PM
    Sunday, April 15, 2018 2:05 PM

Answers

  • You must escape both < >

    Public Class SimpleDemo
        public sub DoingSql
            Dim selectStatement As String =
                    <SQL>
                    Select C1, C2,C3
                    ,Date1
                    ,Date2
                    ,Date3
                    ,Date4
                     From Table WHERE (Date1&gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
                    AND Date1 &lt; DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))
                    </SQL>.Value
    
            Console.WriteLine(selectStatement)
        End sub
    End Class

    Output

    Select C1, C2,C3
    ,Date1
    ,Date2
    ,Date3
    ,Date4
    From Table WHERE (Date1 &gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1 < DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Sunday, April 15, 2018 2:30 PM
    Moderator

All replies

  • You must escape both < >

    Public Class SimpleDemo
        public sub DoingSql
            Dim selectStatement As String =
                    <SQL>
                    Select C1, C2,C3
                    ,Date1
                    ,Date2
                    ,Date3
                    ,Date4
                     From Table WHERE (Date1&gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
                    AND Date1 &lt; DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))
                    </SQL>.Value
    
            Console.WriteLine(selectStatement)
        End sub
    End Class

    Output

    Select C1, C2,C3
    ,Date1
    ,Date2
    ,Date3
    ,Date4
    From Table WHERE (Date1 &gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1 < DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Sunday, April 15, 2018 2:30 PM
    Moderator
  • You must escape both < >

    Public Class SimpleDemo
        public sub DoingSql
            Dim selectStatement As String =
                    <SQL>
                    Select C1, C2,C3
                    ,Date1
                    ,Date2
                    ,Date3
                    ,Date4
                     From Table WHERE (Date1&gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
                    AND Date1 &lt; DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))
                    </SQL>.Value
    
            Console.WriteLine(selectStatement)
        End sub
    End Class


    Hello,

    THank you very much ,

    This is working well,

    From Table WHERE (Date1 &gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1 &lt; DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))

    But This No:

    From Table WHERE (Date1 &gt;=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1 < DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0))

    I used This and It work very well too:

     From Table WHERE (Date1 >=DATEADD(day,DATEDIFF(day,0,GETDATE()),0)
    AND Date1 &#60; DATEADD(day,DATEDIFF(day,0,GETDATE())+1,0))
    so ,Thank you so much.

    Best Regards Bajtitou.


    • Edited by Bajtitou Sunday, April 15, 2018 4:42 PM
    Sunday, April 15, 2018 4:41 PM