如何从sql server数据库中检索图像 [英] how to retrieve image from sql server database
本文介绍了如何从sql server数据库中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我用过的代码。
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Image
Imports System.Data
Imports System.Web.UI.WebControls.Image
Imports System.Web
Imports System.Web.UI
Public Class _Default
Inherits System.Web.UI。 Page
Public sqlcon As SqlConnection = New SqlConnection(server = .; database = batool; Trusted_Connection = yes;)
Public sqlcmd As SqlCommand
Protected Sub Button1_Click(ByVal sender As Object,ByVal e As EventArgs)处理Button1.Click
尝试
Dim picname As String
sqlcon.Open()
sqlcmd =新SqlCommand(从qq中选择照片, sqlcon)
Dim reader As SqlDataReader = sqlcmd.ExecuteReader
if reader.Read Then
picname = reader(photo)
Image1.ImageUrl =(picname)
结束如果
sqlcon.Close()
C ex ex As Exception
MsgBox(ex.Message)
结束尝试
结束Sub
结束类
这是保存在数据库中的URL
C:\ Users \ duaa \Downloads \ test1 \ image.orig \0.jpg
解决方案
请查看以下链接:
http:// www .aspsnippets.com / Articles / display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx
http://www.aspsnippets.com/Articles/检索图像使用文件路径存储在数据库中的ASPNet.aspx [ ^ ]
http://stackoverflow.com/questions/19724742/display-image-in-aspimage-from-getting-path-from-sql-server [ ^ ]
hi everyone. I have save the URL of the image in the database, and I want to retrieve these image in the image control. Can you help me please.
this is the code that I have used.
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Image
Imports System.Data
Imports System.Web.UI.WebControls.Image
Imports System.Web
Imports System.Web.UI
Public Class _Default
Inherits System.Web.UI.Page
Public sqlcon As SqlConnection = New SqlConnection("server=.; database=batool; Trusted_Connection=yes;")
Public sqlcmd As SqlCommand
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Try
Dim picname As String
sqlcon.Open()
sqlcmd = New SqlCommand("select photo from qq", sqlcon)
Dim reader As SqlDataReader = sqlcmd.ExecuteReader
If reader.Read Then
picname = reader("photo")
Image1.ImageUrl = (picname)
End If
sqlcon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
and this is the URL that save in the database
C:\Users\duaa\Downloads\test1\image.orig\0.jpg
解决方案
Please look into the below links :
http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx
http://www.aspsnippets.com/Articles/Retrieve-images-using-a-file-path-stored-in-database-in-ASPNet.aspx[^]
http://stackoverflow.com/questions/19724742/display-image-in-aspimage-from-getting-path-from-sql-server[^]
这篇关于如何从sql server数据库中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文