【问题标题】:How to check is null value in the table?如何检查表中是否为空值?
【发布时间】:2009-07-05 05:21:31
【问题描述】:

使用 MS ACCESS 2003

如何检查access数据库中是否为空值?

我的代码。

Public Function DateToString(dte As Date) As String
Dim d As String
Dim m As String
Dim y As String
d = Day(dte)
m = Month(dte)
y = Year(dte)
If Len(d) = 1 Then d = "0" & d
If Len(m) = 1 Then m = "0" & m
DateToString = y & m & d
End Function


Public Function StringToDate(txt As String) As Date
Dim dte As String
dte = Left(txt, 4) & "-" & Mid(txt, 5, 2) & "-" & Right(txt, 2)
StringToDate = CDate(dte)
End Function




sql1 = "CREATE TABLE MOI (PreDate varchar(50))"
sql2 = "INSERT INTO MOI values('" & StringToDate(rsCardEvent1.Fields("PreDate"))  "')"

从上面的函数中,我想检查如果不为空,那么我的代码就不需要了。

需要 VB 6.0 代码帮助?

【问题讨论】:

  • rsCardEvent1.Fields("DATE") 是字符串吗?

标签: ms-access vb6 ms-access-2003


【解决方案1】:

在数据集字段中检查 Null:

If IsNull(rs("colname")) Then 
  'Field contains a Null Value 
Else 
  'Field does 'not' contain a Null Value 
End If

检查空字符串或空字符串:

If (txt & "") = "" Then 
  ' txt is Null or empty
End If

【讨论】:

  • @Gopal:请出示您的代码;光说没用就不好说了!我发布的方法都经过了尝试和测试。
  • @Mitch Wheat。我发布了我的代码,通过,我在我的代码中使用了你的代码,但它显示“无效使用 NUll”
【解决方案2】:

如果该项目实际上是作为一个字符串来的,那么做:

if not txt is vbNullString then
    ' code here
end if

【讨论】:

  • 它可能不会以字符串形式出现。你可以试试米奇小麦的方法;它似乎更健壮一些。
猜你喜欢
  • 2017-06-11
  • 2015-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-06
  • 1970-01-01
相关资源
最近更新 更多