Home > other >  How to get public holiday table from sql to date picker range in vb.net?
How to get public holiday table from sql to date picker range in vb.net?

Time:05-25

my problem situation is I want the public holiday table from sql connect with the date picker range. So that when user wants to apply for leave they can't pick the date as same as the public holiday. I am using asp.net and vb.net for the date range picker.

The date range picker i use is this

CodePudding user response:

I have solved my problem

    Private Function getHoliday(ByVal strtDate As String, ByVal endDate As String) As DataTable
        Dim dt As New DataTable
        Dim strGetHoliday As String = "SELECT ID,Name FROM holiday WHERE Start_Date=@Start_Date OR End_Date=@End_Date"
        myconn.AddParameter("@Start_Date", MySqlDbType.VarChar)
        myconn.SetParameter("@Start_Date", strtDate)
        myconn.AddParameter("@End_Date", MySqlDbType.VarChar)
        myconn.SetParameter("@End_Date", endDate)

        Try
            myconn.OpenConnection()
            myconn.FillDataTable(dt, strGetHoliday)
            myconn.CloseConnection()
            myconn.ClearAllParameter()

        Catch ex As Exception
            myconn.CloseConnection()
            myconn.ClearAllParameter()
        End Try
        Return dt
    End Function

Then i called the function in datepickerto_DateChanged sub

 Protected Sub datepickerto_DateChanged(sender As Object, e As EventArgs) Handles datepickerto.DateChanged
        Dim dt As DataTable
        dt = getHoliday(datepickerFrom.Text, datepickerto.Text)
        If dt.Rows.Count > 0 Then
            DisplayMessage("Error", "Error", "Public Holiday")
        End If
    End Sub
  • Related