-
Dec 23rd, 2021, 04:22 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Null parameter values and date fields, Access
I would like to know why it is that I am unable to work with a date field/column from an Access database and a parameter.
I know, from past attempts, that if I create a parameter to update a date field that if the parameter value is null then the query will fail to execute.
Code:
UPDATE MyTable SET column=@date
i.e. if @date is null then the query will fail.
I am weary with working around this problem. Can I do something to mitigate this issue. I have looked for answers, but have been unable to find anything that addresses this.
-
Dec 23rd, 2021, 04:42 PM
#2
Re: Null parameter values and date fields, Access
When you assign the parameter's value, pass either DBNull.Value or the date value depending on if the value is null.
For example:
Code:
Dim someDateValue As DateTime
command.Parameters.Add("@date", OleDbType.VarChar, 100).Value = If(someDateValue Is Nothing, DBNull.Value, someDateValue)
-
Dec 24th, 2021, 07:01 PM
#3
Thread Starter
Fanatic Member
Re: Null parameter values and date fields, Access
It took me awhile, but I followed the suggestion and the following code passed the null value.
Code:
If Not String.IsNullOrWhiteSpace(txtEnd.Text) Then
MasterBase.AddParam("@end", txtEnd.Text)
Else
MasterBase.AddParam("@end", Nothing)
End If
Nice to have an occasional easy fix. Additionally, followed the link in the other suggestion and that also provided excellent information. Thanks all.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|