|
-
Sep 4th, 2001, 11:56 PM
#1
Thread Starter
Addicted Member
how 2 pass NULL to Date DataType ?
I'm Importing, exporting data to a text file using the Write/Input method.
when the app. writes 2 a textfile, if the value in the date field is Null, it putz #NULL# in place of the field. When reading frm the same textfile, it givz an error as the variable tt Im using to recieve the value is of date type. How do I go around this problem?
and, how exactly can I pass NULL 2 a Date type variable ?
dim dtest as Date
dtest= NULL
givz error
-
Sep 5th, 2001, 12:00 AM
#2
the value 0 (zero) works like null. It assigns no date.
-
Sep 5th, 2001, 01:47 AM
#3
Registered User
You can't assign a null to a date. The only datatype that accepts null is a variant. So this is the datatype to use when working with nulls.
If you assign a value of zero, you are actually assigning the date 30/12/1899 12:00:00 AM:
Code:
Dim d As Date
d = 0
Debug.Print Format(d, "dd/mm/yyyy hh:mm:ss AM/PM")
-
Sep 5th, 2001, 12:53 PM
#4
Thread Starter
Addicted Member
well since I cant change the data type of the field in the database
(its smalldatetime), I change the datatype of the parameter tt I pass 2 the stored proc.But there is no option for advariant, so I passed adVarchar using a variable of variant datatye. Now, this works fine when there is a Null value, but I cant get it 2 work, when there is a date present in the datefield.
givz error
"Application uses a value of the wrong type for the current operation"
dim xtest as variant
cmd.Parameters.Append .CreateParameter("@TrainingStartDate", adVarChar, adParamInput, 4, xtest)
CREATE PROCEDURE i_EmployeeDetails
@TrainingStartDate varchar,
AS
INSERT INTO EmployeeInfo VALUES(
Convert ( smalldatetime(4) ,@TrainingStartDate ,1 ) ,
-
Sep 5th, 2001, 01:01 PM
#5
You can create a default value for your parameter. So if the parameter is not passed then it will use a default value:
Code:
CREATE PROCEDURE i_EmployeeDetails
@TrainingStartDate smalldatetime = NULL,
AS
BEGIN
INSERT INTO EmployeeInfo VALUES(@TrainingStartDate)
END
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
|