question

CheeFaiy-9148 avatar image
0 Votes"
CheeFaiy-9148 asked YijingSun-MSFT commented

Can i put system datatable together with boolean?

I have a problem which i have datatable for getHoliday and a boolean to check an error when user enter wrong input for example user dont select any value from combobox so it'll show you an error after you click the button submit. the datatable getHoliday is use for when user click any date on holiday it'll not execute when user click button submit. So now, i need a solution for when user click button submit it'll show an error message.
Below is the function for checking.

    Private Function ErrorFree() As Boolean
    
         If lblEmpNO.Text = "" Then
             DisplayMessage("error", "ERROR", "Please Select Employee No!")
             Return False
             Exit Function
         ElseIf lblemployeename.Text = "" Then
             DisplayMessage("error", "ERROR", "Please Select Employee No!")
             Return False
             Exit Function
         ElseIf lbldepartment.Text = "" Then
             DisplayMessage("error", "ERROR", "Please Select Employee No!")
             Return False
             Exit Function
         ElseIf cmbReason.SelectedIndex = -1 Then
             DisplayMessage("error", "ERROR", "Please Select The Reason!")
             Return False
             Exit Function
         ElseIf datepickerFrom.Text = "" Then
             DisplayMessage("error", "ERROR", "Please Select The Date!")
             Return False
             Exit Function
         ElseIf datepickerto.Text = "" Then
             DisplayMessage("error", "ERROR", "Please Select The Date!")
             Return False
             Exit Function
         ElseIf txtRemark.Text = "" Then
             DisplayMessage("error", "ERROR", "Remarks is empty!")
             Return False
             Exit Function
           
         End If
         Return True
     End Function


sql-server-generaldotnet-visual-basicdotnet-aspnet-webforms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Plus, it'll show an error message like the function above when user select date on holiday

0 Votes 0 ·

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered YijingSun-MSFT commented

Hi @CheeFaiy-9148 ,
You said you use the combox and the submit button. However, I don's see any codes you post about these. Please post more reference codes.
When you click the submit button, it will trigger the button click event. And then it will check the combobox 's value. Whether you have trigger the ErrorFree() method?

Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

here is code for submit button

 Protected Sub btnSubmitExternalWorkDutyDetails_Click(sender As Object, e As EventArgs) Handles btnSubmitExternalWorkDutyDetails.Click
     If ErrorFree() = True Then
         If User.IsInRole("HR_Admin") Or User.IsInRole("TAS_HOD") Then
             If InsertExternalWorkDutyDetails(lblhdddnuserid.Text, lblhddnEmployeedeptid.Text) = 1 Then
                 UpdateRunningNo()
                 DisplayMessage("Sucess", "Info", "Work Duty Sucessfully Inserted")
                 LoadEmployeeByuserid(Membership.GetUser.ProviderUserKey)
             End If
         Else
             If InsertExternalWorkDutyDetails(Membership.GetUser.ProviderUserKey, lblhddnEmployeedeptid.Text) = 1 Then
                 UpdateRunningNo()
                 DisplayMessage("Sucess", "Info", "Work Duty Sucessfully Inserted")
                 LoadEmployeeByuserid(Membership.GetUser.ProviderUserKey)
             End If
         End If
     End If
 End Sub

the comobox id is 'cmbReason' it's already there in the first code




0 Votes 0 ·

and here is datatable getHoliday


    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


0 Votes 0 ·

code for combobox

    Private Sub loadcmbReason()
         Dim strLeavetype As String = "SELECT leave_code,leave_type FROM hr_leave_types WHERE others = 'Y' AND `status` = 'Y' ORDER BY leave_type"
    
         Dim dt As New DataTable
         Try
             myconn.OpenConnection()
             myconn.FillDataTable(dt, strLeavetype)
             myconn.CloseConnection()
    
             cmbReason.TextField = "leave_type"
             cmbReason.ValueField = "leave_code"
             cmbReason.DataSource = dt
             cmbReason.DataBind()
         Catch ex As Exception
             myconn.CloseConnection()
         End Try
     End Sub
0 Votes 0 ·

Hi @CheeFaiy-9148 ,
I understand your descriptions. Let me make sure it. You may be have a form. On the form , you have some labels and a combobox. The combobox's data is filled with datatable from the database. You want that if you don't select the combobox and then click the submit button, it will show the error message. However, you don't show now. Right?
Fill datatable and the selectedindex have no conflict. I think there are error messages in your codes. I suggest you could debug to check what's wrong.
You need check these:
1.If it run the btnSubmitExternalWorkDutyDetails_Click().
2.If it run the ErrorFree().
3.If it run the cmbReason.SelectedIndex.
4.If the combobox have data.

By the way,please use English!
Best regards,
Yijing Sun

0 Votes 0 ·

Hi YijingSun, yes all of it run perfectly. my problem is here i want to call getHoliday function in ErrorFree() function, so that when user click the date holiday then click btnSubmitExternalWorkDutyDeails_Click(), it'll show you and error message just like when you dont select any values from cmbReason.SelectedIndex.

0 Votes 0 ·
Show more comments