I have one table which is external_work_duty_details. So i want to do checking when user cannot inserting the same data as existing data. I have no idea on how to write the code
for example : A want to apply on 24/5/2022 until 25/5/2022 but A already applied it with the same date. so here when A click button submit, display message will appear saying A can't apply. A only can apply it IF the existing data is rejected or cancelled BUT IF it's pending or approved A cannot apply. Column Acknowledgement is for the status. deafult 0 = pending. 1 = approved, 2 = rejected and 3 = cancelled.
external_work_duty_details Table
id duty_id employee_no UserId employee_dept Reason Start_date End_date Remarks Acknowledgement
48 D2205-00029 1315 800 3 OUTSTATION 2022-05-17 2022-05-19 out test 3
49 D2205-00030 1511 1342 32 COMPANY TRIP 2022-05-23 2022-05-27 trip test 1
50 D2205-00031 1115 127 3 MEETING 2022-05-25 2022-05-25 meet 1
here is my vb.net code (edit code)
Private Function checkExistingData(ByVal startdate As String, ByVal enddate As String, ByVal intUserid As Integer, ByVal reason As String) As DataTable
Dim dt As New DataTable
Dim strCheck As String = "SELECT * FROM FROM exteral_work_duty_details WHERE Start_Date=@Start_Date, End_Date=@End_Date, UserId=@UserId, Reason=@Reason"
myconn.AddParameter("@Start_Date", MySqlDbType.VarChar)
myconn.SetParameter("@Start_Date", startdate)
myconn.AddParameter("@End_Date", MySqlDbType.VarChar)
myconn.SetParameter("@End_Date", enddate)
myconn.AddParameter("@UserId", MySqlDbType.Int32)
myconn.SetParameter("@UserId", intUserid)
myconn.AddParameter("@Reason", MySqlDbType.String)
myconn.SetParameter("@Reason", reason)
Try
myconn.OpenConnection()
myconn.FillDataTable(dt, strCheck)
myconn.CloseConnection()
myconn.ClearAllParameter()
Catch ex As Exception
myconn.CloseConnection()
myconn.ClearAllParameter()
End Try
Return dt
End Function




i finally have the solution
I use this sql code and write it in store procedures
and it works for me. then i call it in my vb.net code like this
and this
Then i call CheckExistingData() function in ErrorFree() function like this
and lastly, i call the ErrorFree() function in btnSubmitExternalWorkDutyDetails_Click()