1

MS アクセス 2003 の使用

アクセスデータベースでnull値を確認する方法は?

私のコード。

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"))  "')"

上記の関数から、null でないかどうかを確認したい場合、コードは必要ありません。

VB 6.0 コードのヘルプが必要ですか?

4

2 に答える 2

1

データセット フィールドの Null をチェックするには:

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

null または空の文字列を確認するには:

If (txt & "") = "" Then 
  ' txt is Null or empty
End If
于 2009-07-05T05:51:29.883 に答える
0

アイテムが実際に文字列として来る場合は、次のようにします。

if not txt is vbNullString then
    ' code here
end if
于 2009-07-05T05:26:21.383 に答える