"景先生毕设|www.jxszl.com

oracle blob查询转字符串c#代码

2023-01-12 11:03编辑: www.jxszl.com景先生毕设
oracle blob查询转字符串c#代码



///// 查询blob  返回byte[]
        public static byte[] OutputBlob(string cmdText, params OracleParameter[] cmdParms)
        {
            using (OracleConnection con = new OracleConnection(ConnectString))
            {
                OracleCommand command = new OracleCommand();
          
                PrepareCommand(command, con, null, System.Data.CommandType.Text, cmdText, cmdParms);

                command.Connection = con as OracleConnection;

                command.CommandText = cmdText;
                command.CommandType = System.Data.CommandType.Text;
                System.Data.OracleClient.OracleDataReader reader;
                command.Parameters.Clear();
                try
                {
                    reader = command.ExecuteReader();
                }
                catch (OracleException ex)
                {

                    return null;
                }
                catch (Exception ex)
                {
                    return null;
                }

                reader.Read();
                byte[] byteData = new byte[0];
                try
                {
                    byteData = (byte[])(reader[0]);
                }
                catch (Exception ex)
                {
                    reader.Close();
                    return null;
                }
                reader.Close();
                return byteData;
            }
        }


        /// <summary>
        ///转字符串
        /// </summary>
        public string GetStr(string code)
        {
            string strSql = @" select jrft from tab_ndzj where code ='{0}'";
            strSql = string.Format(strSql, code);
            byte[] digitalSign = OutputBlob(strSql);
            String strPIC = string.Empty;
            if (digitalSign != null)
            {
                 strPIC = System.Text.Encoding.Default.GetString(digitalSign);
            }
            return strPIC;
        }
原文链接:http://www.jxszl.com/biancheng/C/165378.html