Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I using for loop to compare access table date and datepicker date using following code, but I receive Null value for next loop. If it is Null then proceed to next row and read the next value and compare it. My codes are as follows:

What I have tried:

VB
Private Sub DtpFrom_LostFocus(sender As Object, e As EventArgs) Handles DtpFrom.LostFocus

	LvMasterReader = LvMasterCmd.ExecuteReader()

        For I = 0 To LEN - 1

            LvMasterReader.Read()

            If LvMasterReader("Mnt") = CmbMonth.Text And LvMasterReader("Yr") = CmbYear.Text And LvMasterReader("SAP_No") = TxtSapID.Text Then
                FND = 1
                FDT = LvMasterReader("From_Date").ToString

	' I Want to check this FDT before convertion 

	' IF IsDBNull (FDT) then
	' Proceed to next row and read the next value before comparing.
	
	' HOW CAN I DO THIS IN FOR LOOP ?
 
                FDT = CDate(FDT)
                FDT = FormatDateTime(FDT, vbShortDate)

                If FDT = FormatDateTime((DtpFrom.Value), vbShortDate) Then

                    MsgBox("Leave Already Posted.....!", vbOKOnly, "FF Leaves")
                    CmbLeaveType.Focus()
                    Exit Sub
                End If
            End If
        Next

  End Sub
Posted
Updated 22-Jul-18 10:35am
v2

1 solution

You can use the IsDBNull function to check if the column contain any non-null value. Here is an example on how to do that. By the way what the For loop doing?

VB
Dim FDT As String
Dim fdtIndex As Integer

For I = 0 To LEN - 1
    If LvMasterReader.Read() Then

'...
'...
        fdtIndex = LvMasterReader.GetOrdinal("From_Date")

        If Not LvMasterReader.IsDBNull(fdtIndex) Then
            FDT = LvMasterReader(fdtIndex).ToString
            FDT = CDate(FDT)
            FDT = FormatDateTime(FDT, vbShortDate)
        Else
            FDT = String.Empty 'reset
        End If
'...
'...
    End If
 Next


SqlDataReader.GetOrdinal Method (String) (System.Data.SqlClient)[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900