Reputation: 1906
I am writing a method to insert data into oracle in C#. While executing this I am getting
error Invalid parameter binding Parameter name: file
My code is:
public static void DatabaseFilePut(MemoryStream fileToPut, OracleConnection con)
{
try
{
const string preparedCommand =
@"INSERT INTO user_account_statement (statement_id,session_key,
login_id,user_id,account_number,from_date,todate,ipaddress,
create_date_time,STATEMENT_FILE)VALUES(1073,
'fe79e0345986b5a439c26f731234868b53f877366f529',
2335,'204254','108142',to_date('2014-08-23 16:45:06','yyyy-mm-dd hh24:mi:ss'),
to_date('2014-08-23 16:45:06','yyyy-mm-dd hh24:mi:ss'),'106.79.126.249',
to_date('2014-08-23 16:45:06','yyyy-mm-dd hh24:mi:ss'), :file)";
using (var sqlWrite = new OracleCommand(preparedCommand, con))
{
sqlWrite.BindByName = true;
var blobparameter=new OracleParameter
{
OracleDbType = OracleDbType.Blob,
ParameterName = "file",
Value = fileToPut
};
sqlWrite.Parameters.Add(blobparameter);
sqlWrite.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
I have checked the parameter part but not getting exactly what's wrong in that.
Upvotes: 0
Views: 14047
Reputation: 77354
The parameter expects a byte array. I'm not aware that it accepts a memory stream as well. So
Value = fileToPut
should be
Value = fileToPut.ToArray()
Upvotes: 2