参考:
Pass a BLOB as a Parameter to an Oracle Package by Using the .NET Managed Provider for Oracle
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q322796
Pass a BLOB as a Parameter to an Oracle Package by Using the .NET Managed Provider for Oracle
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q322796
代码如下:
//以二进制形式保存文件到变量
byte[] file_source = new byte[file_size]; //file_size为要保存的对象的大小
FileStream FileToString =new FileStream(要保存的对象的路径,FileMode.Open);
BinaryReader br = new BinaryReader(FileToString);
long count=0;
while(count < file_size)
{
file_source[count] = br.ReadByte();
count=count+1;
}这样file_source就保存了,直接保存到数据库就行了
在SQL中是设置一个字段,类型为image就行了(其实在这个类型可以存储任何东西不仅仅是图片,也可以是超大图片,超大文本…………)
然后直接把上面代码的file_source二进制数组赋值就可以了思路就是这样的。希望对你有用
System.Text.Encoding.ASCII.GetBytes();
System.Text.Encoding.Unicode.GetBytes();
System.Text.Encoding.UTF8.GetBytes();Byte2String
System.Text.Encoding.ASCII.GetString();
System.Text.Encoding.Unicode.GetString()
System.Text.Encoding.UTF8.GetString();
OleDbCommand myCommand = new OleDbCommand();
myCommand.CommandType = System.Data.CommandType.StoredProcedure;
myCommand.CommandText = "ins_news";
myCommand.Connection = myConnection;
System.Byte[] byteContent = System.Text.Encoding.Unicode.GetBytes(strContent); myCommand.Parameters.Add( new OleDbParameter("@i_content", OleDbType.LongVarBinary) );
myCommand.Parameters["@i_content"].Value = byteContent;try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
catch( OleDbException e )
{
sucsess = false;
throw e;
}报出错误:ORA-01460: 未实现或无理的转换请求 。orcale里面content的类型是long
是不是我用OleDbType.LongVarBinary的类型存入不行?