Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have update query though which i am passing datetime value , i have use cDate to convert string to datetime , but problem is when i pass null values it throughs error , how to pass null values into datetime datatype in Ms access

this is my code

VB
Dim iresult1 As Integer = UtilityClass.ProcessData("update PM11 SET PCODE='" & txtPcode.Text & "' ,PNAME='" & txtPartyName.Text & "',AUTMOB='" & txtAutMob.Text & "',ADD1='" & txtAdd1.Text & "',ADD2='" & txtAdd2.Text & "',ADD3='" & txtAdd3.Text & "',CITY='" & txtCity.Text & "',PHNO='" & txtPHNO.Text & "',PIN='" & txtPin.Text & "',PNAME1='" & txtPName1.Text & "',PNAME2='" & txtPName2.Text & "',QNAME1='" & txtQName1.Text & "',RADD1='" & txtRADD1.Text & "',RADD2='" & txtRADD2.Text & "',RCITY='" & TXTRCITY.Text & "',DOB= CDate(IIf(Isnull( '" & txtDOB.Text & "'),Null,'" & txtDOB.Text & "')),AREACODE='" & txtArea.Text & "',DOAN='" & txtAnvDate.Text & "',BLDGRP='" & txtBdgroup.Text & "',RDGNO='" & txtRdbNo.Text & "',MST='" & txtMST.Text & "',CST='" & txtCST.Text & "',LICEXDATE=CDate(IIf(Isnull('" & txtLicXdate.Text & "'),"null",'" & txtLicXdate.Text & "')),PMLDATE='" & txtFreePaidUptoDt.Text & "',DLICNO20='" & txtlicNo20.Text & "',DLICNO21='" & txtLicNo21.Text & "',DLICNO20C='" & txtLicNo20C.Text & "',DLICNO20B='" & txtLicNo20B.Text & "',DLICNO21B='" & txtLicN021B.Text & "',DLICNO20D='" & txtLicNo20D.Text & "',SCODE='" & type & "' ,email_id='" & Trim(txtemail.Text) & "' WHERE PCODE='" & txtPcode.Text & "'")
Posted
Updated 22-Dec-13 21:08pm
v2

Have a look here: Microsoft Access Data Types[^]

MSDN wrote:
Date values must be either delimited according to the ODBC canonical date format or delimited by the datetime delimiter ("#"). Otherwise, Microsoft Access will treat the value as an arithmetic expression and will not raise a warning or error.

For example, the date "March 5, 1996" must be represented as {d '1996-03-05'} or #03/05/1996#; otherwise, if only 03/05/1993 is submitted, Microsoft Access will evaluate this as 3 divided by 5 divided by 1996. This value rounds up to the integer 0, and since the zero day maps to 1899-12-31, this is the date used.
 
Share this answer
 
Access stores datetime values internally using a double floating point value. The double value 0.0 corresponds to the date 12/31/1899. So you can check your date value and pass this date if it is null or invalid. You can also pass the string 'Null'. Then Access sets the field to the above start date.
 
Share this answer
 
Comments
[no name] 23-Dec-13 6:21am    
Usually in SQL it is NULL ;)
Jochen Arndt 23-Dec-13 6:31am    
You are right. But Access does not accept NULL as datetime value when using SQL commands. Passing the string 'Null' is the trick.
[no name] 23-Dec-13 6:33am    
Thank you for this feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900