使用vs2005,数据库为sql2005,是将数据存在binary字段下吧。

解决方案 »

  1.   

     /// <summary>
            /// 读取文件到数据库
            /// </summary>
            /// <param name="path"></param>
            /// <returns></returns>
            public byte[] ReadFile(string path)
            {
                this.log.error("NoticeInfoAdd", "ReadFile", "Start");
                try
                {
                    FileStream myStream = new FileStream(path,
                                                             FileMode.Open,
                                                             FileAccess.Read);
                    byte[] myImageBuffer = new byte[myStream.Length];
                    myStream.Read(myImageBuffer, 0, (int)myStream.Length);
                    myStream.Close();
                    return myImageBuffer;
                }
                catch (Exception ex)
                {
                    this.log.error("NoticeInfoAdd", "ReadFile", ex.Message);
                }
                finally
                {
                    this.log.error("NoticeInfoAdd", "ReadFile", "End");
                }
                return null;
            }数据库最好设置为image
      

  2.   

    先把文件转成二进制流,再传到varbinary字段,对这个毫无头绪啊,以前没接触过。求教应该如何弄