Visual Basic 6. ADO 2.8
I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)
The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.
However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?
Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!
Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.
Cheers
Stu
Option Explicit
Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset
Private Sub Command1_Click()
Dim sSQL As String
sSQL = "select prikey, anyDate from tbl where prikey = 1"
RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText
Debug.Print RS.Fields("anyDate").Value
'"2005-03-13"
RS.Fields("anyDate").Value = dateserial(1,1,1)
Debug.Print RS.Fields("anyDate").Value
'"0100-01-01" 'close: only 100 years out!
RS.Fields("anyDate").Value = 0
Debug.Print RS.Fields("anyDate").Value
'"00:00:00" 'looks promising but updates DB with '1899-12-31
RS.updatebatch
End Sub
Private Sub Form_Load()
Set CN = New ADODB.Connection
CN.CursorLocation = adUseClient
CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=**SYSTEM_NAME**;" & _
"DBQ=**CATALOG_NAME**;" & _
"Uid=**USERNAME**;" & _
"Pwd=**PASSWORD**;" & _
"Commpression = 1;" & _
"Signon = 2;" & _
"Blocksize=512;" & _
"Prefetch=1;"
End Sub