data type mismatch in criteria expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tejasagrawal
    New Member
    • Feb 2013
    • 2

    data type mismatch in criteria expression

    I am firing an insert query like this in C# to MS ACCESS 07 Database
    Code:
    var expiry = dateTimePicker1.Text;
     string instr = "insert into MST_QUOTATION values(";
                     instr += txtID.Text;
                     instr += "," + txtcustid.Text;
                     instr += ",'" + txtCustname.Text; 
                     instr += "','" + txtAdd1.Text;
                     instr += "','" + txtZip.Text;
                     instr += "'," + txtContact.Text;
                     instr += ",'" + txtEmail.Text;
                     instr += "','" + expiry;
                     instr += "','" + expiry;
                     instr += "');";
    
                     cmd = new OleDbCommand(instr, cn);
                  cmd.ExecuteNonQuery();
    // Now i m getting error like this
    data type mismatch in criteria expression
    please help me
    Last edited by Meetee; Feb 12 '13, 11:13 AM. Reason: Use code tags [/CODE] around code
  • Mikkeee
    New Member
    • Feb 2013
    • 94

    #2
    Looks like you need to check your query string against the data types in your table. Print your instr variable to the immediate window and post it along with your MST_QUOTATION table schema.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      If expiry is a date, then Access uses # symbols to demarcate dates.

      Also, you should be aware that your code is succeptible to SQL injection attacks. You should escape your dynamic values.
      Last edited by Rabbit; Feb 12 '13, 04:32 PM.

      Comment

      Working...