简体   繁体   中英

Cannot Update Row In Oracle DB Using C# Library

When I want to update row with type 'date' in oracle database through asp.net C# method it gives the following error:

error: ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP

code:

string query = String.Format("update mms_meetings m set m.end_date = :end_date where m.id = :id");

    OracleCommand cmd = new OracleCommand("", GetDBConnection());
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = query;

    OracleParameter opId = new OracleParameter();
    opId.DbType = DbType.Int32;
    opId.Value = meetId;
    opId.ParameterName = "id";

    cmd.Parameters.Add(opId);

    OracleParameter opDateEnd = new OracleParameter();
    opDateEnd.DbType = DbType.DateTime;
    opDateEnd.Value = dateEnd;
    opDateEnd.ParameterName = "end_date";
    cmd.Parameters.Add(opDateEnd);

    cmd.ExecuteNonQuery();
    cmd.Dispose();

    CloseDBConnection(); 

1) You must send the exact format for your date as specified in your table column. Check default format for your date column. Like

'yyyy/MM/dd'

2) If you are using OleDb or ODBC Connection, they both use positional parameters so order of adding the parameters is very important. Try changing the order of your parameter to see if it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM