Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:41:47+00:00 2026-06-16T00:41:47+00:00

I am trying to implement CoolStorage in my project, but am running into an

  • 0

I am trying to implement CoolStorage in my project, but am running into an issue when using date parameters. When I pass in null as the date parameter it adds the record successfully, but if I pass an actual date through I get an error when calling .Save() to write the new record to the database. I have got the (Activa) CoolStorage source code and have found the point where it fails, but can’t figure how to fix it.

The code where it fails is as follows (specifically the dbCommand.ExecuteNonQuery() line):

internal int ExecuteNonQuery(string sqlQuery, CSParameterCollection parameters)
{
    long logId = Log(sqlQuery, parameters);

    IDbCommand dbCommand = CreateCommand(sqlQuery, parameters);

    try
    {
        dbCommand.ExecuteNonQuery();

        return 1;
    }
    catch (InvalidOperationException)
    {
        return -1;
    }
    finally
    {
        LogEnd(logId);
    }
}

The sqlQuery contains:

insert into [Schedule] ([TaskID],[StartTime],[MondayYn],[TuesdayYn],[WednesdayYn],[ThursdayYn],[FridayYn],[SaturdayYn],[SundayYn],[DefaultSysuserID],[DefaultTeamID],[ActiveYn]) 
values (@P17,@P18,@P19,@P20,@P21,@P22,@P23,@P24,@P25,@P26,@P27,@P28)

@P18 contains the offending date, which is a CSParameter object with a value of:

{17/12/2012 18:52:44}

Also, the database being used is Access. The error that’s thrown is a OldDbException which reads {“Data type mismatch in criteria expression.”}.

Can anyone offer any advice on how to resolve this?

EDIT: The Schedule StartTime field is defined in the Schedule table as Date/Time. I need it to have its required propetry set to True, but have disabled in order to test adding records by leaving StartTime out. The parameters are being applied via the CoolStorage classes as follows:

Schedule schedule = Schedule.New();
schedule.TaskID = task.TaskID;
schedule.StartTime = DateTime.Now;
schedule.MondayYn = true;
schedule.TuesdayYn = true;
schedule.WednesdayYn = true;
schedule.ThursdayYn = true;
schedule.FridayYn = true;
schedule.SaturdayYn = false;
schedule.SundayYn = false;
schedule.DefaultSysuserID = sysuser.SysuserID;
schedule.DefaultTeamID = sysuser.SysuserTeams.First().TeamID;
schedule.ActiveYn = true;
schedule.Save();

When I comment out the Schedule.StartTime = DateTime.Now line I can successfully add records, otherwise I get the error described above. I cannot change the format to text without editing my ORM mapping class, which will no doubt cause errors elsewhere. I guess I could alter the CoolStorage DataProvider class, but I’m assuming that this shouldn’t be necessary?

EDIT2: As a test I intercepted the SQL posted above to remove the @P18 reference and hard code the date in its place and the record added correctly:

insert into [Schedule] ([TaskID],[StartTime],[MondayYn],[TuesdayYn],[WednesdayYn],[ThursdayYn],[FridayYn],[SaturdayYn],[SundayYn],[DefaultSysuserID],[DefaultTeamID],[ActiveYn]) 
values (@P17,#2012-12-01 12:00:00#,@P19,@P20,@P21,@P22,@P23,@P24,@P25,@P26,@P27,@P28)

I also tried modifying the value of the parameter by casting it as a string formatted as #yyyy-MM-dd hh:mm:ss# however I still received the Data type mismatch in criteria expression error.

EDIT3: I have fixed it by following Abhishek’s (edit – also Dean’s) suggestion of converting the DateTime to a string by amending the CSParameterCollection class as follows. Hopefully this won’t cause problems if I decide to use a different database but it’s fixed it for Access:

public CSParameter this[string name]
{
    get
    {
        CSParameter parameter;

        _parameterMap.TryGetValue(name, out parameter);

        if (parameter.Value.GetType().Equals(typeof(DateTime)))
        {
            DateTime date = (DateTime)parameter.Value;
            string dateString = date.ToString("yyyy-MM-dd hh:mm:ss");
            parameter.Value = dateString;
        }

        return parameter;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:41:47+00:00Added an answer on June 16, 2026 at 12:41 am

    I strongly feel that the problem is because the parameters are not in the same order when you are adding them to the parameter collection.

    Make sure that they are in the same order and this applies to both sql statements or stored procedures.

    ADO.NET does not support named parameters when using an OLEDB provider, and since you are connecting to an Access DB, you are actually using an OLEDB provider. So the order of the parameters does matter.

    If they are in order and it’s still not working, then I think that it might be an issue with the DateTime. Try converting it to string before adding it as a parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying implement a way to recursively template using jsRender. The issue is, my
Trying to implement the new FP 10.1 Global error handler into my projects but
Just trying to implement mobFox into my app, but having trouble to make it
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
I am trying implement a SQL INSERT command into my MS Access database using
Trying to implement Piwik using REST API over http but need a little help.
Trying to implement something similar to qtip, but using a table that compares the
Iam trying to implement JMS using eclipse.But when I tried to save the code,
I am trying implement a most recent widget into my tumblr post. So far,
Trying to implement 3-layer (not: tier, I just want to separate my project logically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.