简体   繁体   中英

Issue in retrieving the date field from the DB2 query in vbscript

Whenever the table has Date column which has the default value as 0001-01-01, I am getting the below error. Please help me to correct this problem.

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Mon, 31 Mar 2014 13:09:51 UTC

Message: Invalid procedure call or argument: 'showList.fields(...).Value' Line: 139 Char: 7 Code: 0

dim fso,conn

sqlStr = "select * from "& tablename & " "& whereclause & ""

Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
fpath1= sFTPTemp & tablename &".csv"

set fso = CreateObject("Scripting.FileSystemObject")

set Conn = CreateObject("ADODB.connection")
Conn.ConnectionTimeout = 60
Conn.CommandTimeout = 60

Conn.open "Provider=IBMDADB2;Hostname=1.1.1.1;Protocol=TCPIP;Port=50000;Database=" & dbalias &      ";Uid=" & Userid & " ;Pwd= "&  Pwd & ";"
dim a, showList, intcount
set a = fso.createtextfile(fPath1)
set showList = conn.execute(sqlStr)

if showlist.eof  then
   a.write "No Rows found"
else
   for intcount = 0 to showList.fields.count -1
   if intcount <> showList.fields.count-1 then
      a.write """" & showList.fields(intcount).name & ""","
   else
      a.write """" & showList.fields(intcount).name & """"
   end if
   next
   a.writeline ""
   do while not showList.eof
   for intcount = 0 to showList.fields.count - 1
   if intcount <> showList.fields.count - 1 then
      a.write """" & showList.fields(intcount).value & ""","
   else
      a.write """" & showList.fields(intcount).value & """"
   end if
   next
   a.writeline ""
   showList.movenext
  loop
end if
showList.close
set showList = nothing
set a = nothing

According to the Docs , your 'default date' is out of range:

In Microsoft Windows, the range of valid dates is January 1, 100 AD through December 31, 9999 AD; the ranges vary among operating systems.

A simple test:

>> WScript.Echo DateAdd("yyyy", -1900, Date)
>>
31.03.114
>> WScript.Echo DateAdd("yyyy", -2000, Date)
>>
Error Number:       5
Error Description:  Invalid procedure call or argument

supports the assumption that VBScript chokes when trying to convert the database value to a VBScript Date.

As I doubt that your real world problem involves dates like 0001-01-01, the correct remedy would be to store NULL in your table(s) for unknown dates and - perhaps - set the default to something that makes sense in your specific domain and fall in VBScript's date range.

If you have to deal with the problem in your script, your options are

  • use the queries to get an additional flag for out-of-range dates and look at this before you try to access the date value
  • change the queries to get the date value stringified, write a 'accessTheDates' function that looks at the string value and returns a valid date or Null/a valid special date
  • isolate the date access in a small function with a local On Error Resume Next that returns a valid date or - in case of error - Null/a valid special date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM