Data type mismatch in criteria expression [C#, MSAccess]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kermit
    New Member
    • Aug 2007
    • 16

    Data type mismatch in criteria expression [C#, MSAccess]

    Hi.
    Here's the problem.
    I use C# application [forms] to access MSAccess database.
    I want to get id's of all records containing some phrase and order results by date (a field in the table).

    here's the code:
    OleDbCommand cmd = new OleDbCommand("s elect id, endDate from audits where objectId ='" + (int)data[0] + "' order by endDate DESC", conn);
    try
    {
    conn.Open();
    OleDbDataReader aReader = cmd.ExecuteRead er(); <-- here i get error*
    }
    (...)

    * error: "Data type mismatch in criteria expression"
    If I delete '+ "' order by endDate DESC' part of the query it works.

    How to order my results by date?
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    I haven't seen this in a query before - (int)data[0] - int is obviously data type. What are you trying to do?

    Comment

    • Kermit
      New Member
      • Aug 2007
      • 16

      #3
      data is a array of objects. I'm casting object to int.

      I was trying to get id's of all rows that contain certain data, and order them by date.

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Try putting the array value in a parameter first and then into your query. Also easier to debug. HTH.

        Comment

        Working...