日期:2014-05-17  浏览次数:20768 次

c# blob图片问题
oracle 10G,字段类型为:blob。里面存的是图片。怎么才能把图片查出来,比如,将它转为二进制在传给另外的地方。
在网上查了一下。
通过datareader,byte[] b=(byte[])dr["Photo"]
dataset:byte[] m_bynewblob = (byte[])myDateSet.Tables[0].Rows[0]["Photo"]; 
这样都会报错,读不出来dr["Photo"],这一列肯定存在。

不知道哪位有经验的朋友,帮忙看一下,万分感谢。



------解决方案--------------------
C# code

//以前我写过一个测试的,是没问题的,返回是值的长度而已
        protected long GetLength(int id)
        {
            OracleConnection conn = null;
            OracleCommand cmd = null;
            OracleDataReader dr = null;
            string sConn = "data source=orcl;user id=zhangandli;password=1;";
            try
            {
                conn = new OracleConnection(sConn);
                cmd = new OracleCommand("select b from t where id=1", conn);
                conn.Open();
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                if (dr.Read())
                {
                    if (dr[0].ToString() != "")
                    {
                        byte[] blob = (byte[])dr[0];
                        return blob.Length;
                    }
                }
            }
            catch
            {
                return 0;
            }
            finally
            {
                dr.Close();
            }
            return 0;
        }