Type mismatch in Date

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Type mismatch in Date

    Hi!

    I have a problem with my vbscript code...
    my database is a access 2000 db.

    here is the code Im running:

    ----------------------------------------------------------------------------
    ----------------------------
    sqlBetal = "SELECT * FROM Faktura WHERE FakturaNR=" &
    Request.QueryString("FakturaNR")
    Set rsBetal = Server.CreateObject("ADODB.Recordset")
    rsBetal.Open sqlBetal, conn, 3, 3
    rsBetal("Betalt") = True
    rsBetal("BetaltSum") = Request.Form("BetaltSum")
    rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    vbShortDate)

    rsBetal.Update
    rsBetal.close
    Set rsBetal = Nothing
    Response.Redirect "Faktura.asp"
    ----------------------------------------------------------------------------
    ----------------------------

    I get this error:

    ----------------------------------------------------------------------------
    ----------------------------

    Provider error '80020005'

    Type mismatch.

    /faktura/Faktura_betal.asp, line 45

    ----------------------------------------------------------------------------
    ----------------------------
    line 45 looks kie this:

    rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    vbShortDate)

    The Request.Form("BetaltDato") has the <%=date()%> value.....

    The BetaltDato field in the database is formated as Date/time

    What could be wrong????

    If I change it to: rsBetal("BetaltDato") = Date() the code runs
    with outh problem..


    So I tried this:

    --<%= Date() %>--<%= FormatDateTime(Request.Form("BetaltDato"), vbShortDate)
    %>--

    The output looks like this:

    --07.05.2004--07.05.2004--

    ITS THE SAME!!!!! grr.... hehe

    Any idea?????


    Christopher Brandsdal


    Christopher Brandsdal Guest

  2. Similar Questions and Discussions

    1. Type mismatch error
      This query works fine on a live server using an MSSQL database: <cfquery name="qIndex" datasource="#appDSN#" username="shampoo"...
    2. Interface Type Mismatch
      This works in Java, so it is not clear why Actionscript does not implement it the same way. If an instance of a class that implements an Interface...
    3. Type mismatch?
      Hi i'm getting a type mismatch error, anyone tell me why pls? conn.Execute "DELETE FROM Bmemo WHERE (tDate <= '" & date() & "')" tDate is a...
    4. Type Mismatch
      I'm at my wits end here. I am getting type mismatch error in a ASP page when I try to multiply decimals*integers. This shouldn't be this difficult....
    5. Type Mismatch again
      Hi, One page passes a strIssueNo to another, so on the 2nd page: Dim IssueNo IssueNo = Request.Item("strIssueNo") This 2nd page is designed...
  3. #2

    Default Re: Type mismatch in Date

    Check if the date is null in the data that throws the error. You cannot
    format a NULL to a date format (ToShortDate()).

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ************************************************
    Think Outside the Box!
    ************************************************
    "Christopher Brandsdal" <cwbrandsdal@c2i.net> wrote in message
    news:%23mRe1YFNEHA.628@TK2MSFTNGP11.phx.gbl...
    > Hi!
    >
    > I have a problem with my vbscript code...
    > my database is a access 2000 db.
    >
    > here is the code Im running:
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    > sqlBetal = "SELECT * FROM Faktura WHERE FakturaNR=" &
    > Request.QueryString("FakturaNR")
    > Set rsBetal = Server.CreateObject("ADODB.Recordset")
    > rsBetal.Open sqlBetal, conn, 3, 3
    > rsBetal("Betalt") = True
    > rsBetal("BetaltSum") = Request.Form("BetaltSum")
    > rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    > vbShortDate)
    >
    > rsBetal.Update
    > rsBetal.close
    > Set rsBetal = Nothing
    > Response.Redirect "Faktura.asp"
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    >
    > I get this error:
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    >
    > Provider error '80020005'
    >
    > Type mismatch.
    >
    > /faktura/Faktura_betal.asp, line 45
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    > line 45 looks kie this:
    >
    > rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    > vbShortDate)
    >
    > The Request.Form("BetaltDato") has the <%=date()%> value.....
    >
    > The BetaltDato field in the database is formated as Date/time
    >
    > What could be wrong????
    >
    > If I change it to: rsBetal("BetaltDato") = Date() the code runs
    > with outh problem..
    >
    >
    > So I tried this:
    >
    > --<%= Date() %>--<%= FormatDateTime(Request.Form("BetaltDato"),
    vbShortDate)
    > %>--
    >
    > The output looks like this:
    >
    > --07.05.2004--07.05.2004--
    >
    > ITS THE SAME!!!!! grr.... hehe
    >
    > Any idea?????
    >
    >
    > Christopher Brandsdal
    >
    >

    Cowboy Guest

  4. #3

    Default Re: Type mismatch in Date

    Christopher Brandsdal wrote:
    > Hi!
    >
    > I have a problem with my vbscript code...
    > my database is a access 2000 db.
    >
    > here is the code Im running:
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    > sqlBetal = "SELECT * FROM Faktura WHERE FakturaNR=" &
    > Request.QueryString("FakturaNR")
    > Set rsBetal = Server.CreateObject("ADODB.Recordset")
    > rsBetal.Open sqlBetal, conn, 3, 3
    > rsBetal("Betalt") = True
    > rsBetal("BetaltSum") = Request.Form("BetaltSum")
    > rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    > vbShortDate)
    The initial problem is delimiters (or lack thereof).
    The Date() and Now() functions return a Variant whose subtype is Date - no
    delimiters are needed.
    The FormatDateTime function is returns a Variant whose subtype is String
    which is supposed to represent a date: a date "literal". Date literals must
    be delimited by hash marks (#). So the initial solution is to do this:

    sDate=FormatDateTime(Request.Form("BetaltDato"), vbShortDate)
    rsBetal("BetaltDato") = "#" & sDate & "#"

    However, the problem is deeper than that: your server's short date setting
    is resulting in a non-ISO compliant date format. Dates should be entered in
    databases in ISO format. With Access, the format should be YYYY-MM-DD. See
    here for help in converting your date to the proper format (if you can't
    figure out how to do it yourself, that is):
    [url]http://www.aspfaq.com/show.asp?id=2260[/url].

    HTH,
    Bob Barrows



    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  5. #4

    Default Re: Type mismatch in Date

    A couple of issues. (a) are you using Request.Form or Request.QueryString?
    (b) do not use ADODB.Recordset to perform UPDATEs. Use a single, atomic
    statement. (c) always validate your input and make sure that the data is as
    expected *before* sending it to the database. (d) never use vbShortDate,
    since this setting can change. For Access, you should always use YYYY-MM-DD
    for date values.

    Taking (b) and (d) in mind only, how about:

    dt = cdate(Request.Form("BetaltDato"))
    dt = year(dt) & "-" & right("00" & month(dt), 2) & "-" & right("00" &
    day(dt), 2)
    SQL = "UPDATE Faktura SET Betalt=-1, BetaltSum=" & _
    Request.Form("BetaltSum") & ", BetaltDato=#" & dt & "#" & _
    " WHERE FakturaNR=" & Request.QueryString("FakturaNR")
    conn.execute SQL, , 129

    Better yet, Access can calculate the date() itself, so why bother running
    into formatting issues and passing that extra data over the wire?

    SQL = "UPDATE Faktura SET Betalt=-1, BetaltSum=" & _
    Request.Form("BetaltSum") & ", BetaltDato=Date()" & _
    " WHERE FakturaNR=" & Request.QueryString("FakturaNR")
    conn.execute SQL, , 129

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]




    "Christopher Brandsdal" <cwbrandsdal@c2i.net> wrote in message
    news:#mRe1YFNEHA.628@TK2MSFTNGP11.phx.gbl...
    > Hi!
    >
    > I have a problem with my vbscript code...
    > my database is a access 2000 db.
    >
    > here is the code Im running:
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    > sqlBetal = "SELECT * FROM Faktura WHERE FakturaNR=" &
    > Request.QueryString("FakturaNR")
    > Set rsBetal = Server.CreateObject("ADODB.Recordset")
    > rsBetal.Open sqlBetal, conn, 3, 3
    > rsBetal("Betalt") = True
    > rsBetal("BetaltSum") = Request.Form("BetaltSum")
    > rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    > vbShortDate)
    >
    > rsBetal.Update
    > rsBetal.close
    > Set rsBetal = Nothing
    > Response.Redirect "Faktura.asp"
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    >
    > I get this error:
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    >
    > Provider error '80020005'
    >
    > Type mismatch.
    >
    > /faktura/Faktura_betal.asp, line 45
    >
    > --------------------------------------------------------------------------
    --
    > ----------------------------
    > line 45 looks kie this:
    >
    > rsBetal("BetaltDato") = FormatDateTime(Request.Form("BetaltDato"),
    > vbShortDate)
    >
    > The Request.Form("BetaltDato") has the <%=date()%> value.....
    >
    > The BetaltDato field in the database is formated as Date/time
    >
    > What could be wrong????
    >
    > If I change it to: rsBetal("BetaltDato") = Date() the code runs
    > with outh problem..
    >
    >
    > So I tried this:
    >
    > --<%= Date() %>--<%= FormatDateTime(Request.Form("BetaltDato"),
    vbShortDate)
    > %>--
    >
    > The output looks like this:
    >
    > --07.05.2004--07.05.2004--
    >
    > ITS THE SAME!!!!! grr.... hehe
    >
    > Any idea?????
    >
    >
    > Christopher Brandsdal
    >
    >

    Aaron Bertrand - MVP Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139