c#通过oledb上传图片到Oracle BLOL字段的问题
代码如下,运行后没报错,但图片并没有写入到PIC字段,反而将该字段置为null了private void button1_Click(object sender, EventArgs e)
{
FileInfo imgFile = new FileInfo(@"C:\abc.jpg");
byte[] imgByte = new byte[imgFile.Length];//1.初始化用于存放图片的字节数组
FileStream imgStream = imgFile.OpenRead();//2.初始化读取图片内容的文件流
imgStream.Read(imgByte, 0, Convert.ToInt32(imgFile.Length));//3.将图片内容通过文件流读取到字节数组
imgStream.Close();
imgStream = null;
imgFile = null;
OleDbConnection con = new OleDbConnection("Provider=MSDAORA.1:;Data Source=***;User ID=***;PassWord=***");
con.Open();
OleDbCommand ocmd = new OleDbCommand("Update item_picture set PIC=? where SKU_ID='111307145' ", con);
ocmd.Parameters.Add("pPIC ", OleDbType.Binary, imgByte.Length).Value = imgByte;
ocmd.ExecuteNonQuery();
ocmd.Dispose();
con.Close();
} --------------------编程问答--------------------
private void button1_Click(object sender, EventArgs e)--------------------编程问答-------------------- 以前版本中,那个OleDbType.Binary限制了32K的长度,超过后就无法写入了。现在的版本中,无限制长度。
{
byte[] imgByte = File.ReadAllBytes(@"C:\abc.jpg");
OleDbConnection con = new OleDbConnection("Provider=MSDAORA.1:;Data Source=***;User ID=***;PassWord=***");
con.Open();
OleDbCommand ocmd = new OleDbCommand("Update item_picture set PIC=?pPIC where SKU_ID='111307145' ", con);
ocmd.Parameters.Add("pPIC", OleDbType.Binary, imgByte.Length).Value = imgByte;
ocmd.ExecuteNonQuery();
ocmd.Dispose();
con.Close();
}
对于以前的版本,基本做法是利用OracleLob来实现的,部分代码如下:
cmd.CommandType = CommandType.Text;--------------------编程问答-------------------- avphoenixi,还是写不进去。
cmd.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;";
cmd.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
OracleLob tempLob = (OracleLob)cmd.Parameters[0].Value;
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
byte[] tempbuff = in_param.value as byte[];
tempLob.Write(tempbuff, 0, tempbuff.Length);
tempLob.EndBatch();
idparam.Value = tempLob;
qldsrx,我的jpg文件并没超过32K --------------------编程问答-------------------- sql 语句里把
PIC=?pPIC
换成
PIC=:pPIC
这样试下 --------------------编程问答-------------------- 报错了:并非所有变量都已关联
补充:.NET技术 , C#