本文介绍了如何检查空日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨朋友, 我使用for循环来比较访问表日期和datepicker日期使用以下代码,但我收到下一循环的Null值。如果它为Null,则继续下一行并读取下一个值并进行比较。我的代码如下: 我尝试过: 私有 Sub DtpFrom_LostFocus(发件人如 对象,e As EventArgs)句柄 DtpFrom.LostFocus LvMasterReader = LvMasterCmd.ExecuteReader() 对于 I = 0 LEN - 1 LvMasterReader.Read() 如果 LvMasterReader( Mnt)= CmbMonth.Text 和 LvMasterReader( Yr)= CmbYear.Text 和 LvMasterReader( SAP_No)= TxtSapID.Text 然后 FND = 1 FDT = LvMasterReader( From_Date)。ToString ' 我想在转换前检查此FDT ' IF IsDBNull(FDT)然后 ' 继续下一行并阅读比较之前的下一个值。 ' 我如何为循环做这个? FDT = CDate (FDT) FDT = FormatDateTime(FDT,vbShortDate) 如果 FDT = FormatDateTime((DtpFrom.Value),vbShortDate)那么 MsgBox( 已经发布.....!,vbOKOnly, FF离开) CmbLeaveType.Focus() 退出 Sub 结束 如果 结束 如果 下一步 结束 Sub 解决方案 您可以使用 IsDBNull 函数来检查列是否包含任何非空值。这是一个如何做到这一点的例子。那么For循环做什么呢? Dim FDT As String Dim fdtIndex As Integer For I = 0 LEN - 1 如果 LvMasterReader.Read()那么 ' ... ' ... fdtIndex = LvMasterReader.GetOrdinal( From_Date) 如果 不 LvMasterReader.IsDB Null(fdtIndex)然后 FDT = LvMasterReader(fdtIndex).ToString FDT = CDate (FDT) FDT = FormatDateTime(FDT,vbShortDate) 否则 FDT = 字符串 .Empty ' 重置 结束 如果 ' ... ' ... 结束 如果 下一步 SQLDATA Reader.GetOrdinal方法(字符串)(System.Data.SqlClient) [ ^ ] 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:Private Sub DtpFrom_LostFocus(sender As Object, e As EventArgs) Handles DtpFrom.LostFocusLvMasterReader = 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 解决方案 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?Dim FDT As StringDim fdtIndex As IntegerFor 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 NextSqlDataReader.GetOrdinal Method (String) (System.Data.SqlClient)[^] 这篇关于如何检查空日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 06:40