Question

When I try to insert a record into a table using C#, I am getting the following error,

Message = "ORA-01036: illegal variable name/number\n"
Source = "System.Data.OracleClient"
StackTrace = "   at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)\r\n   at System.Data.OracleClient.OracleParameterBinding.Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, Bo...
TargetSite = {Void CheckError(System.Data.OracleClient.OciErrorHandle, Int32)}

My code:

Int32 intLogID = 0;
strSQL = "INSERT INTO log_data(log_id, response_msg) "
                                        + "VALUES(?, ?)";
OracleCommand cmd = new OracleCommand(strSQL, conn);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("log_id", OracleType.Int32).Value = intLogID;
cmd.Parameters.Add("response_msg", OracleType.VarChar, 256).Value = strResMsg;
cmd.ExecuteNonQuery();

My table structure:

LOG_ID          NOT NULL NUMBER(18) 
RESPONSE_MSG    VARCHAR2(256)

I am able to successfully insert into the table When I tried it manually using,

INSERT INTO log_data(log_id, response_msg)
values (1067365, 'test'); 

I even tried int intLogID = 0; and cmd.Parameters.Add("log_id", OracleType.Number).Value = intLogID;

Also Int32 with Number binding combination and int with Int32 binding combinations.

But still getting same error. What could be the problem?

Was it helpful?

Solution

I think you should have your query as

"INSERT INTO log_data(log_id, response_msg) VALUES(:log_id,:response_msg)"

Coz you are supplying those specific parameters like

cmd.Parameters.Add("log_id", OracleType.Number).Value = intLogID;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top