Chinaunix首页 | 论坛 | 博客
  • 博客访问: 232548
  • 博文数量: 55
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 530
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-22 17:59
文章分类

全部博文(55)

文章存档

2015年(2)

2011年(1)

2010年(1)

2009年(18)

2008年(16)

2007年(17)

我的朋友

分类: 系统运维

2007-04-22 19:08:52

可以先在一个页面上输出图像,img再绑定这个页面就行了,具体做法如下:
例如:输出的图像的页面名字叫:imageshow.aspx,在imageshow.aspx.vb的Page_Load()函数中把存在数据库中的图片加载在此页面上,具体代码如下:
         Dim DataBaseNameList(30) As String
        Dim GH_Number As Integer
        Dim SQL_String_GHList As String
        SQL_String_GHList = "Data Source=" + DataSouseName + "; Integrated Security=SSPI;Initial Catalog=" + "GreenHouseList"
        Dim con As SqlClient.SqlConnection = New SqlClient.SqlConnection(SQL_String_GHList)
        Dim com As New SqlClient.SqlCommand
        Dim ds As DataSet
        com.CommandText = "SELECT * FROM SaveImage"
        com.Connection = con
        Dim da As New SqlDataAdapter(com)
        Try
            con.Open()
            ds = New DataSet
            da.Fill(ds, "SaveImage")
            con.Close()
        Catch ex As Exception
        End Try
        GH_Number = ds.Tables("SaveImage").Rows.Count   '获取表的行数
        Dim strTemp As String
        Dim i As Integer = 0
        Dim data() As Byte
        For i = 0 To GH_Number - 1 Step 1
            strTemp = ds.Tables("SaveImage").Rows(i)("GH_RealName")
            If strTemp = strName Then
                data = ds.Tables("SaveImage").Rows(i)("Image")
                Response.BinaryWrite(data)
                Response.End()
            End If
        Next i
    End Sub
其中:Response.BinaryWrite(data)就是从数据库中以字节形式读出图片。
然后,再在要显示的页面上,也就是加载image控件的页面的Page_Load()的函数中写上如下代码:Image1.Attributes.Item("src") = "ImageShow.aspx"就ok了!你所要显示的图片就显示在Image控件上了

 
阅读(3904) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~