Asp.net 上传文件到Oracle数据库Blob格式

private void clob(byte[] bytes, int ContentLength)
    {
        OracleConnection conn = new OracleConnection("TODO:yourconnect");
        try
        {
            conn.Open();
            OracleTransaction trans = conn.BeginTransaction();


            OracleCommand command = new OracleCommand();
            command.Transaction = trans;
            command.Connection = conn;
            command.CommandType = CommandType.Text;


            //获取临时clob
            command.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :templob := xx; end;";
            command.Parameters.Add(new OracleParameter("templob", OracleType.Blob)).Direction = ParameterDirection.Output;
            command.ExecuteNonQuery();


            OracleLob tempblob = (OracleLob)command.Parameters[0].Value;
            //end 获取临时clob
            tempblob.Write(bytes, 0, ContentLength);
            tempblob.Position = 0;
            trans.Commit();


            command.Parameters.Clear();
            command.CommandText = " insert into subprojectfiles values(subprojectfiles_id.nextval,:subprojectid,:filetype,:name,:diskfile) ";
            

            command.Parameters.Add(new OracleParameter("subprojectid","67"));
            command.Parameters.Add(new OracleParameter("filetype","1"));
            command.Parameters.Add(new OracleParameter("name", FileUpload1.FileName));
            command.Parameters.Add(new OracleParameter("diskfile", OracleType.Blob, ContentLength,
                ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, tempblob));


            command.ExecuteNonQuery();


            this.Response.Write("insert OK");


        }
        catch (Exception ex)
        {
            this.Response.Write(ex.Message);
        }
        finally
        {
            if (conn != null)
                conn.Close();
        }
    }

网上找来的,收藏下~

原文http://www.cnblogs.com/OwenWu/archive/2011/04/05/2005521.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值