网站公告列表     庆祝我站图形图象及站长在线查询工具(下载)栏目开通!  [五月雪电脑教程网  2007年5月21日]            努力打造国内最新最快最丰富的软件信息开放平台!一直致力于提供新鲜、全面、专业的软件信息和知识。软件资讯,无限精彩!  [五月雪  2006年2月23日]            新版本进入测试阶段,请各位网友多提宝贵意见!  [管理员  2006年1月24日]        
加入收藏
设为首页
繁體中文
您现在的位置: 五月雪电脑网 >> 网络编程 >> VB >> 文章正文
怎样在vb.net中将图片存入SQL Server 2000并能读出来使用
怎样在vb.net中将图片存入SQL Server 2000并能读出来使用
作者:佚名 文章来源:本站原创 点击数: 更新时间: 2007-1-21 15:39:04
广告载入中...
 

数据库中建一个Img表,其中包含一个Img字段,类型为Image或Binary
'将Bytes存入数据库
Dim Stream As New IO.MemoryStream
PictureBox1.Image.Save(Stream, System.Drawing.Imaging.ImageFormat.Bmp)
Stream.Flush()
Dim Bytes As Byte() = Stream.ToArray
Dim SQL As String = "insert into Img values (@bytes) "
Dim command As New SqlClient.SqlCommand(SQL, Connection)
command.Parameters.Add("@bytes", SqlDbType.Binary).Value = Bytes
command.ExecuteNonQuery

'读取
Dim Command As New SqlClient.SqlCommand(SQL, Connection)
Dim Reader As SqlClient.SqlDataReader = Command.ExecuteReader()
Dim Bytes as Byte()=Reader.Item("Img")
Dim mStream As New IO.MemoryStream
mStream.Write(Bytes, 0, Bytes.Length)
mStream.Flush()
Dim Img As New Bitmap(mStream)
PictureBox1.Image = Img

文章录入:llm64    责任编辑:llm64 
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最 新 热 门
    最新热门信息载入中...
    最 新 推 荐
    最新推荐信息载入中...
    相 关 文 章
    相关文章信息载入中...
    相 关 评 论
    相关评论信息载入中...

    Copyright @ 2005 2006 五月雪
    中华人民共和国信息产业部ICP备案号: 闽ICP备 05014026

    本站服务器和带宽由心网网络友情提供
    统计进行中...统计进行中...

    ASP常用的操作数据库结构…
    ASP动态网页制作中使用S…
    ASP调用SQL Server视图和…
    在ASP.NET中访问SQL 200…
    将以前写的SQL2分查找法…
    Asp+Sql 对数据库的各种…
    Asp+Sql 对数据库的各种…
    在PHP中全面阻止SQL注入…
    在PHP中全面阻止SQL注入…
    关于如何保障Winnt +asp…
     姓 名:
     评 分:
    1分 2分 3分
    4分 5分
     内 容: