开发者

Set date field to null

I am trying to set a date field to null in a MS SQL Server 2005 database.

I am using VBScript on asp pages.

The column in the DB allows for nulls. But when I try to add a record and not pass anything along to the date field, or try to set the field back to Null, I get this error:

Provider error '80020005'

Type mismatch.

/add_client_notes.asp, line 142

Line 142 is: rs("client_not开发者_StackOverflowes_duedate") = client_notes_duedate

Here is all the code:

<% 
    clientnotes_id = request("clientnotes_id")
    client_notes_duedate = request("client_notes_duedate")
    if client_notes_duedate = "" then
        client_notes_duedate = Null
    end if

    openSQL("SELECT * FROM client_notes WHERE client_notes_id=" & clientnotes_id)
    rs("client_notes_duedate") = client_notes_duedate
    rs.update

%>

I have tried sending an empty value and a NULL value but both return the same error.

When I send the date value along it works great.

How can I set client_notes_duedate back to NULL?


Are you able to refactor this code into:

execSomeSqlStatement("UPDATE client_notes SET client_notes_duedate = NULL 
 WHERE client_notes_id=" & clientnotes_id)

Perhaps refactor a bit more to avoid the SQL injection vulnerability?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜