Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Null in Date Field 2

Status
Not open for further replies.

DebbieC

Programmer
Mar 29, 2001
168
US
I'm having a problem entering a Null in a date field when the date is not available yet.

I tried the following:

If "WribRecd" = "" Then
objCmd.Parameters.Append _
objCmd.CreateParameter("WribRecd", adDBTimeStamp, adParamInput, 4, DBNull)
Else
objCmd.Parameters.Append _
objCmd.CreateParameter("WribRecd", adDBTimeStamp, adParamInput, 4, PrepareString(WribRecd))
End If

I get the following error message:

ADODB.Command error '800a0d5d'

Application uses a value of the wrong type for the current operation.

/hr/wrib/_admin/processupdatelog.asp, line 181

Line 181 is where it says:

objCmd.Parameters.Append _
objCmd.CreateParameter("WribRecd", adDBTimeStamp, adParamInput, 4, PrepareString(WribRecd))

Can someone help me?

 
a TimeStamp column is not the same as DateTime. Timestamp is a binary column and is automatically generated by sql server.
 
change adDBTimeStamp to adDBDate

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks gmmastros. I changed it but unfortunately I am still receiving the same error message.

Is there something else I can try?
 
Yup. Tell us what PrepareString() does.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 


The problem is in your code, the condition will be always false even when WribRecd is null, so PrepareString(WribRecd) will give you an error when WribRecd is null.

Try change ' If "WribRecd" = "" Then ...' to 'If WribRecd = "" Then ...'
 

Code:
 If "WribRecd" = "" Then ... 

  to 

 If WribRecd = "" Then ...
 
Man, if I had to do CreateParameter calls in all my ADODB code I would shoot myself. If it were me, I would make that datetime parameter optional (look into optional SP params, but you do that by assigning the param to NULL in this case), and I would use the 'refresh' method of ADO once given the SP name to 'stub out' all the parameters, then just use the Parameters() collection (with index of param name or ordinal) for setting the values of each param.

See the link:


Oh, and the "refresh" call does generate one round trip, but hey, for most applications that use SPs that is okay overhead.

TJR
 

or
Code:
  If "WribRecd" = "" Then ... 

  to 

 If WribRecd is nothing Then ...
 
is nothing" works only with objects.

Good eye about double quotes though. [smile]

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Thanks everyone for the information. I tried removing the quotes around the variable but I got an error message so I put it back. However there must have been something else wrong with the code at that time. I removed the quotes and it's working now.

TJRTech - Thanks for the information. I don't understand it but I will read up on it. Thanks for the link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top