当前位置:编程学习 > C#/ASP.NET >>

执行Oracle存储过程返回一个值

create or replace function NA_GetPhoto
(
  CardID  in    number,            --卡信息ID
  CardType  in    number default     --卡类型,1普通,0临时
)
return blob;

这个要怎么获取返回的blob值,并展示在图片框中。 --------------------编程问答-------------------- 没人回复吗??? --------------------编程问答-------------------- 参考:

public void ReadBlob(int idData,string fileName, string id, string blob, string tableName)
        {
            string connString = "server=oratest;User ID=kttest;Password=test";
            using(conn = new OracleConnection(connString))
            {
                try
                {
                    conn.Open();
                    OracleCommand cmd = conn.CreateCommand();

                    // 利用事务处理
                    OracleTransaction transaction = cmd.Connection.BeginTransaction();
                    cmd.Transaction = transaction;

                    // 获得 OracleLob 指针
                    string sql = "select " + blob + " from " + tableName + " where " + id + " = " + idData;
                    cmd.CommandText = sql;
                    OracleDataReader dr = cmd.ExecuteReader();
                    dr.Read();
                    OracleLob tempLob = dr.GetOracleLob(0);
                    dr.Close();

                    // 读取 BLOB 中数据,写入到文件中
                    FileStream fs = new FileStream(fileName,FileMode.Create);
                    int length = 1048576;
                    byte[] Buffer = new byte[length];
                    int i;
                    while((i = tempLob.Read(Buffer,0,length)) > 0)
                    {
                        fs.Write(Buffer,0,i);
                    }
                    fs.Close();
                    tempLob.Clone();
                    cmd.Parameters.Clear();

                    // 提交事务
                    transaction.Commit();
                }
                catch(Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
}
--------------------编程问答--------------------             using (OracleConnection conn = new OracleConnection(strConn))
            {
                try
                {
                    OracleCommand cmd = new OracleCommand("存储过程名称", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("卡号", 123456);  //给输入参数赋值 
                    cmd.Parameters.AddWithValue("卡类型", 0);
                    OracleParameter parReturn = new OracleParameter("return", OracleType.Blob);
                    parReturn.Direction = ParameterDirection.ReturnValue;   //参数类型为ReturnValue                    
                    cmd.Parameters.Add(parReturn);
                    if (conn.State == ConnectionState.Open) { }
                    else
                    {
                        conn.Open();
                    }

                    cmd.ExecuteNonQuery();
                    conn.Close();

}


这样返回的parReturn 对象 ,我要怎么读取到??? 我是要将得到的Blob文件流加载到图像框中。 --------------------编程问答--------------------             using (OracleConnection conn = new OracleConnection(strConn))
            {
                try
                {
                    OracleCommand cmd = new OracleCommand("存储过程名称", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("卡号", 123456);  //给输入参数赋值 
                    cmd.Parameters.AddWithValue("卡类型", 0);
                    OracleParameter parReturn = new OracleParameter("return", OracleType.Blob);
                    parReturn.Direction = ParameterDirection.ReturnValue;   //参数类型为ReturnValue                    
                    cmd.Parameters.Add(parReturn);
                    if (conn.State == ConnectionState.Open) { }
                    else
                    {
                        conn.Open();
                    }

                    cmd.ExecuteNonQuery();
                    conn.Close();

}


这样返回的parReturn 对象 ,我要怎么读取到??? 我是要将得到的Blob文件流加载到图像框中。
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,