如果您使用的是桌面应用程序,这就是解决方案
Private Sub SqlBlob2File(ByVal DestFilePath As String)
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cn As New SqlConnection("server=localhost;integrated security=yes;database=NorthWind")
Dim cmd As New SqlCommand("SELECT Picture FROM Categories WHERE CategoryName='Test'", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim ms As New System.IO.MemoryStream(b)
Me.PictureBox1.Image = System.Drawing.Image.FromStream(ms)
End Sub
这是您可能想要查看的链接:http: //support.microsoft.com/kb/321900/en-us
asp.net 解决方案
在网页或 aspx 页面的情况下,您只能在来自 Url 的网页上显示图像,首先应该有一个图片网页,因为 webform2 必须只有一个图片框。此页面是 webform1 的图像。
通过这种方式,您可以根据需要在页面上放置尽可能多的图片,当然这取决于您制作相同数量的伪页面(并且不要给它们起相同的名称)。
我希望这将是一个不错的页面。
\\ webform1 上必须有一个图像框、一个按钮和一个标签
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand("SELECT FileName, PictureID FROM Picture", conn)
da = New SqlDataAdapter(cmd)
cbd = New SqlCommandBuilder(da)
dsPictures = New DataSet
da.Fill(dsPictures)
Me.Image1.Visible = False
ListBox1.AutoPostBack = True
Try
ListBox1.DataSource = dsPictures.Tables(0)
ListBox1.DataTextField = "FileName"
ListBox1.DataValueField = "PictureID"
ListBox1.DataBind()
Catch sqlExc As SqlException
Me.Label1.Text = "Database Error" 'sqlExc.ToString
Catch exc As Exception
Me.Label1.Text = "Datbase Connection Failed!"
End Try
conn.Close()
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Session.Item("img") = ListBox1.SelectedItem.Value
Image1.Visible = True
Image1.ImageUrl = "http://localhost/testSQLPlaatjesWeb/WebForm2.aspx"
End Sub
/// \\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection(connStr)
Dim sqlstr As String = String.Format("SELECT Picture FROM Picture WHERE
(PictureID = {0})", CInt(Session.Item("img")))
Dim cmd As New SqlCommand(sqlstr, conn)
conn.Open()
Dim rdr As SqlDataReader = cmd.ExecuteReader()
rdr.Read()
Response.BinaryWrite(CType(rdr.Item("Picture"), Byte()))
rdr.Close()
conn.Close()
End Sub
///