本文介绍了Asp.net检索母版页中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,程序员在这里遇到了问题.如您所见,IVE添加了此代码以通过母版页检索数据库中的图片.问题是香港专业教育学院有一个错误(不是语法)原因导致当我运行我的程序时图片显示出来,但在无光泽页面中的设计没有.请帮忙
这是我的代码:
Hello programmers got a problem here. As you see ive added this code to retrieve pictures on my database via master page. The problem is ive got an error (not syntax) cause when i run my program the picture shows up but the design in maste page doesnt. Please help
here is my code:
Dim cn As SqlConnection = New SqlConnection("Data Source=ML0003135586\SQLEXPRESS;Initial Catalog=ecom;Integrated Security=True")
'Dim stream As New MemoryStream()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lbltime.Text = DateTime.Today.ToString("dd-MMM-yyyy")
Dim str As String
str = Convert.ToString(Session("username"))
lblName.Text = str
retrieve()
End Sub
Protected Sub out_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles out.Click
Session("Username") = ""
Response.Redirect("Login.aspx")
End Sub
Protected Sub btnhome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnhome.Click
If lblName.Text = "" Then
Response.Redirect("Login.aspx")
Else
Response.Redirect("Home.aspx")
End If
End Sub
Public Sub retrieve()
Dim sql As String = "Select * from Images where ([ImageID]=@ImageID) "
cn.Open()
Dim cmd As SqlCommand = New SqlCommand(sql, cn)
cmd.Parameters.AddWithValue("@ImageID", lbl1.Text)
Try
Dim myDataReader As SqlDataReader
myDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = "image/jpeg"
Response.BinaryWrite(myDataReader("Image"))
Loop
cn.Close()
Catch SQLexc As SqlException
End Try
End Sub
推荐答案
这篇关于Asp.net检索母版页中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!