none
I get the follwoing error"Data type mismatch in criteria expression" RRS feed

  • Question

  • i get the following error when i m going to delete row from my Access database using c# .net and my code is

     

    while (subEnum.MoveNext() == true && stringEnum.MoveNext() == true)

    {

    ListViewItem.ListViewSubItem subItem = (ListViewItem.ListViewSubItem)subEnum.Current;

    strtype = reader.GetDataTypeName(ncolumn++);

    if (subItem.Text != "")

    {

    if (bFirst == false)

    builder.Append(" AND");

    else

    bFirst = false;

    builder.Append(" [");

    builder.Append(stringEnum.Current);

    if (strtype == "DBTYPE_14")

    builder.Append("] = ");

    else

    builder.Append("]= '");

    builder.Append(subItem.Text);

    if (strtype != "DBTYPE_14")

    builder.Append("'");

    }

    }

     

    what would i do wrong plzz help me to resolve this problem

    Saturday, October 13, 2007 12:41 AM

Answers

  • If the date fields are actually date data types in the database table then as Bonnie was indicating you will have to treat them as dates and not string values. The date literals should be enclosed in pound signs and not single quotes.

     

    An even better way to handle this would be to use Command Parameters instead, so you don't have to worry about the syntax issue.

     

    Tuesday, October 16, 2007 2:51 PM

All replies

  • Where is your error?  Probably the stringEnum.Current because it's not a string, it's most likely an int (which is the default).

     

    Try this:

     

    builder.Append(stringEnum.Current.ToString());

    Saturday, October 13, 2007 8:03 PM
  • no i have a same problem it didn't work my final delete string is

     

    DELETE FROM Pinformation

    WHERE  [Member_no] = 'A3'

    AND [Nic_number] = '42101-4518342-2'

     AND [First_name] = 'Sunan'

    AND [Last_name] = 'Hashmi'

    AND [Middle initial] = 'Miss'

    AND [Birth_date] = '11/11/1982 12:00:00 AM'

    AND [Adress] = 'A-143' AND [city] = 'karachi'

    AND [province] = 'Sindh'

    AND [Postal code] = 63400

    AND [P-no] = 6314586

    AND [email] = 'sunan@hotmail.com'

    AND [Exp_date] = '8/6/2008 12:00:00 AM'

     

     

    Tuesday, October 16, 2007 1:25 PM
  • It might be the date fields, I'm not sure what format Access expects them to be. How you getting your Delete string? Are you building the string yourself? Have you thought about using Parameters instead?

    Tuesday, October 16, 2007 2:10 PM
  • If the date fields are actually date data types in the database table then as Bonnie was indicating you will have to treat them as dates and not string values. The date literals should be enclosed in pound signs and not single quotes.

     

    An even better way to handle this would be to use Command Parameters instead, so you don't have to worry about the syntax issue.

     

    Tuesday, October 16, 2007 2:51 PM