本文介绍了如何从sql server数据库中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我已将图像的URL保存在数据库中,我想在图像控件中检索这些图像。你能帮我吗?这是我用过的代码。
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
解决方案
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
解决方案
这篇关于如何从sql server数据库中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!