Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i tried to insert picture in oracle database using System.Data.OracleClient namespace not oracle.dataAccess but it gives me that error

{"Failed to convert parameter value from a OracleBinary to a Byte[]."}

please could any one help me in that
Posted

marjavic wrote:
Failed to convert parameter value from a OracleBinary to a Byte[]


Error explains it by itself.

Wrong casting is going on in your code. Resolve it.
Further read this: OracleBinary to Byte[] Conversion[^]
 
Share this answer
 
//you have to read the picture into a byte[] first:

FileStream fls;

fls = new FileStream("picturepath", FileMode.Open, FileAccess.Read);

byte[] blob = new byte[fls.Length];

fls.Read(blob, 0, System.Convert.ToInt32(fls.Length));

fls.Close();

//insert into the table.
//the datatype for the picture must be "Blob"
string st = "insert into candidates (photo) values(:BlobParameter )";

OracleParameter blobParameter = new OracleParameter();

blobParameter.OracleType = OracleType.Blob;

blobParameter.ParameterName = "BlobParameter";

blobParameter.Value = blob;

OracleCommand cmnd = new OracleCommand(st, c);

cmnd.Parameters.Add(blobParameter);

cmnd.ExecuteNonQuery();


if you still have a problem, send your codes for a little help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900