读书人

ado.net 操作oracle中blob字段解决方法

发布时间: 2012-08-11 20:50:31 作者: rapoo

ado.net 操作oracle中blob字段
在通过adapter写入image类型的数据时,想像操作sql server的image字段那样,直接把转换成byte()的数据付给字段,结果不能完成,请问大家有什么好的方法没有,谢谢。

[解决办法]
存储过程中
UPDATE 表名
SET blob字段 = EMPTY_BLOB()
WHERE ...;
UPDATE 表名
SET blob字段 = 传入参数(blob类型)
WHERE...;

vb.net中
Dim cmd As New OracleCommand()
cmd = conn.CreateCommand()
cmd.Transaction = tx
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()

Dim tempLob As OracleLob
tempLob = cmd.Parameters(0).Value
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite)
tempLob.Write(tempBuff, 0, tempBuff.Length)
tempLob.EndBatch()

cmd.Parameters.Add(New OracleParameter("blob参数名", OracleType.Blob)).Value = tempLob
后面执行存储过程

读书人网 >VB Dotnet

热点推荐