INSERTING DATE

Discussion in 'ASP General' started by dthmtlgod, Oct 11, 2004.

  1. dthmtlgod

    dthmtlgod Guest

    I am trying to insert a date into a date field through my website. The date
    is pre-populated with todays date. I am getting a type mismatch error. The
    Access DB is setup as a Date/Time Short Date field.

    Here is the SQL string. Any ideas?

    Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
    PrinterName, UserName) VALUES ('MaintDate', 'SA', 'Maintenance',
    'PrinterName', 'UserName')")
     
    dthmtlgod, Oct 11, 2004
    #1
    1. Advertising

  2. dthmtlgod wrote:
    > I am trying to insert a date into a date field through my website.
    > The date is pre-populated with todays date. I am getting a type
    > mismatch error. The Access DB is setup as a Date/Time Short Date
    > field.
    >
    > Here is the SQL string. Any ideas?
    >
    > Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA,
    > Maintenance, PrinterName, UserName) VALUES ('MaintDate', 'SA',
    > 'Maintenance', 'PrinterName', 'UserName')")


    This statement is attempting to put the word 'MaintDate' into a field that
    will only accept date/time values.

    Check out these posts:
    http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=

    http://www.google.com/groups?hl=en&...ows&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=10&sa=N

    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], Oct 11, 2004
    #2
    1. Advertising

  3. With what you have, you're trying to insert the literal text, "MaintDate."
    You want to insert a date, i.e.

    Conn.Execute "INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
    PrinterName, UserName) VALUES (#" & Date & "#,'SA'......)"

    Also, do you mean to insert the literal text of SA, Maintenance,
    Printername, etc.? Or are they variables? If those are variables in your
    code, they are not going to be evaluated when you execute your INSERT. All
    you'll see is the actual literal text, MaintDate, SA, etc. Remember, you're
    just building a string here, so if you want to concatenate variable values,
    you have to do just that - concatenate the values.

    sSQL = "INSERT INTO.... VALUES (#" & Date & "#,'" & SA & "','" & Maintenance
    & "','" & PrinterName & "','" & Username & "')"

    Response.Write sSQL

    Ray at home

    "dthmtlgod" <> wrote in message
    news:ui9$...
    >I am trying to insert a date into a date field through my website. The
    >date
    > is pre-populated with todays date. I am getting a type mismatch error.
    > The
    > Access DB is setup as a Date/Time Short Date field.
    >
    > Here is the SQL string. Any ideas?
    >
    > Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
    > PrinterName, UserName) VALUES ('MaintDate', 'SA', 'Maintenance',
    > 'PrinterName', 'UserName')")
    >
    >
    >
     
    Ray Costanzo [MVP], Oct 11, 2004
    #3
  4. "dthmtlgod" <> wrote in message
    news:ui9$...
    >I am trying to insert a date into a date field through my website. The
    >date
    > is pre-populated with todays date. I am getting a type mismatch error.
    > The
    > Access DB is setup as a Date/Time Short Date field.
    >
    > Here is the SQL string. Any ideas?
    >
    > Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
    > PrinterName, UserName) VALUES ('MaintDate', 'SA', 'Maintenance',
    > 'PrinterName', 'UserName')")


    Use parameters

    Set cmd.ActiveConnection = conn
    cmd.CommandText = "insert into blah (dt) values(?)" ' simplified sample
    cmd.CommandType = adCmdText
    cmd.Parameters.Append cmd.CreateParameter(, adDBDate, 1, , Date)
    cmd.Execute ,, adExecuteNoRecords


    >
    >
    >
     
    Egbert Nierop \(MVP for IIS\), Oct 12, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    617
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,295
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    530
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    734
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    415
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page