如果您正在使用的桌面應用程序,這是解決
私人小組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