首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# blob图片有关问题

2012-09-25 
c# blob图片问题oracle 10G,字段类型为:blob。里面存的是图片。怎么才能把图片查出来,比如,将它转为二进制在

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;        } 

热点排行