可以先在一个页面上输出图像,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) |