Select Today (Current Day) records from database using Web Service in ASP.Net

makumbi
 
on Aug 27, 2022 06:41 AM
294 Views

How can i modify this webservice to display only records that have been entered today

thanks in advance

<WebMethod>
Public Function GetCustomers() As List(Of Customer)
    Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand("SELECT admno,Name,age,Phone,sex FROM Student")
            cmd.Connection = con
            Dim Customers As List(Of Customer) = New List(Of Customer)()
            con.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                While sdr.Read()
                    Customers.Add(New Customer() With {
                        .admno = sdr("admno").ToString(),
                        .Name = sdr("Name").ToString(),
                         .age = sdr("age").ToString(),
                          .Phone = sdr("Phone").ToString(),
                        .Sex = sdr("sex").ToString()
                    })
                End While
            End Using
            con.Close()
            Return Customers
        End Using
    End Using
End Function
 
Public Class Customer
    Public Property admno As String
    Public Property Name As String
    Public Property age As String
    Public Property Phone As String
    Public Property Sex As String
End Class

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 27, 2022 06:59 AM

Use where condition and check with GetDate function in the select query.

SELECT admno,Name,age,Phone,sex FROM Student WHERE CAST(DateColumn AS DATE) = CAST(GETDATE() AS DATE)