Inserting a Null value in BLOB field in Oracle
-
I have a Blob field in a table in oracle database. Some times i need to put null values into this field This is what iam doing in my C# Code byte[] blobTest = new byte[0]; string insert = "INSERT INTO exampel VALUES(:test)"; OracleParameter test = new OracleParameter(); test.OracleType = OracleType.Blob; test.ParameterName = "test"; test.Value = blobTest; con.Open(); cmd = new OracleCommand(insert, con); cmd.Parameters.Add(test); cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); Its throwing up an error ORA-01459 invalid length for variable if i change byte[] blobTest = new byte[1]; in the above code its working. Basically how do i pass in a null value for a blob field in oracle database. Thanks kal
-
I have a Blob field in a table in oracle database. Some times i need to put null values into this field This is what iam doing in my C# Code byte[] blobTest = new byte[0]; string insert = "INSERT INTO exampel VALUES(:test)"; OracleParameter test = new OracleParameter(); test.OracleType = OracleType.Blob; test.ParameterName = "test"; test.Value = blobTest; con.Open(); cmd = new OracleCommand(insert, con); cmd.Parameters.Add(test); cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); Its throwing up an error ORA-01459 invalid length for variable if i change byte[] blobTest = new byte[1]; in the above code its working. Basically how do i pass in a null value for a blob field in oracle database. Thanks kal
Could you please replace these lines below
test.OracleType = OracleType.Blob; test.ParameterName = "test"; test.Value = blobTest;
with these linestest.OracleType = OracleType.Blob; test.IsNullable = true; test.ParameterName = "test"; test.Value = null;
i haven't done anything in oracle yet but it sounds related to your problem ;D and instead of setting the value to a bytearray consisting of one byte, you should try to put a c# null value on it because the developers probably implemented a c# null to oracle null conversion ;D