如果您正在使用的桌面应用程序,这是解决
私人小组SqlBlob2File(BYVAL DestFilePath作为字符串)
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页面的情况下,你只能从一个网址的网页显示的图像中,首先应该是一个图片的网页作为webform2只有一个图片框应该是那里。此页面是webform1的图像。
这样你可以把尽可能多的图片,只要你想在页面上,这取决于 当然,你做伪页面相同数量的(并且不给他们 相同名称)。
我希望这将是一个不错的网页。
\\ 必须有一个imagebox,一个按钮,并在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
///
可能的复制:[从Binarydata转换为图像控件在asp.net](http://stackoverflow.com/q/7390983/55209),[显示图像从数据库在ASP.net与C#](http://stackoverflow.com/ q/6987433/55209),[Ho w在Asp.net的图像控件中显示数据库中的图像?(http://stackoverflow.com/q/2482104/55209) – 2012-04-05 06:45:37
你真的很喜欢你的shift/capslock键,不是吗? – ThiefMaster 2012-04-05 08:05:39
是的,我知道这是一个不好的做法,但我总是声明我的变量L AND CLE CLE :) :) – Dev 2012-04-05 14:09:56