Data type mismatch in criteria expression

Discussion in 'Databases' started by mambo, Jun 27, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi
    I am caught in the most unexpected place around! I have done several websites with Ms Access 2003 databases and dont remember any failing to insert data. This one just wont accept new records from aspx pages. Both update and delete are working fine, but insert just throws this mismatch error. Below is my sql statements:

    SELECT * FROM [SourceOfInfo]
    UPDATE [SourceOfInfo] SET [Source] = ?, [Description] = ?, [DateStamp] = ? WHERE [SourceID] = ?
    INSERT INTO SourceOfInfo(Source, Description, DateStamp) VALUES (?, ?, ?) - this one just wont work!
    DELETE FROM [SourceOfInfo] WHERE [SourceID] = ?

    My thoughts: cant be in the connection string because the other statements are working; my database has referential integrity in all relations; the date formats? i have checked this - i typed in date as 03/03/07, which looks acceptable format; tried also 03/03/03 00.00.00 but still didnt work. My primary key (SourceID) is autonumbered and the date is set in the database as default now().

    Could somebody find it?

    Mambo
     
  2. Hi,
    Inserts can be a bit tricky.
    Often debugging with hard coded values can help.

    The way I've done inserts with ASP.NET and Access is like this:
    INSERT INTO SourceOfInfo (Source, Description, DateStamp) VALUES ('sSource', 'Description', 'sDateStamp')

    The only difference there is the values are encapsulated.
    If that doesn't work and you still get an error I'd suspect you may need to perform a conversion.
    Possibly your DateStamp.
    Salute,
    Mark
     
  3. Thanks, Mark.

    I have noticed something quiteinteresting with my code:

    When I had:

    INSERT INTO SourceOfInfo(Source, Description, DateStamp) VALUES (?, ?, ?)

    result was data type mismatch

    So I removed the date values(?) so that the user does not have to supply it, ie

    INSERT INTO SourceOfInfo(Source, Description) VALUES (?, ?)

    Then I supplied Source as ME; and Description as TEST.

    The result, however, was

    Source = Null
    Description = ME (the value i supplied for source!!)
    DateStamp = correctly posted as todays date

    I suspect there is a transpositioning happening which I cant yet understand - probably my course of problem with date type mismatch?


    Mambo
     
  4. Yes indeed, probably a data mismatch for the data stamp.
    It's been about a year since I've done anything with Access DBs, I'm getting rusty with them. [​IMG]
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page