概述
----------单层体系结构
<%@ Page Language="vb" %><%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<script runat=server>
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim strImageID as String = Request.QueryString("id")
Dim myConnection As New SqlConnection("Data Source=.;Initial Catalog=mxh;User Id=sa;Password=;")
Dim myCommand As New SqlCommand("Select PersonImageType, PersonImage from Person Where PersonID=" _
+ strImageID, myConnection)
Try
myConnection.Open()
Dim myDataReader as SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = myDataReader.Item("PersonImageType")
Response.BinaryWrite(myDataReader.Item("PersonImage"))
Loop
myConnection.Close()
Catch SQLexc As SqlException
End Try
End Sub
</script>
</HEAD>
<body>
<form runat="server" ID="Form1"></form>
</body></HTML>
----------三层体系结构
---界面层
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ReadImage.aspx.vb" Inherits="ShopGoByGo.WebModules.Product.Web.ReadImage" %>
<HTML>
<HEAD>
</HEAD>
<body><form runat="server" ID="Form1">
<FONT face="宋体"></FONT>
</form></body></HTML>
---表示层
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim productImagesClass As New ProductBusiness.Product(Request.QueryString("id"))
Dim myDataReader As SqlDataReader = productImagesClass.GetProductImage()
Do While (myDataReader.Read())
Response.BinaryWrite(myDataReader.Item("ProductPicture"))
Loop
End Sub
---业务层
#Region "返回指定产品的产品Product_First表里的图片"
Public Function GetProductImage() As SqlDataReader
Dim theProduct As New Data.Product(mySettings.ConnectionString)
Return theProduct.GetProductImage(myProductId)
End Function
#End Region
---数据层
#Region "根据指定的ProductID返回产品的图片"
Public Function GetProductImage(ByVal productId As Integer) As SqlDataReader
' 创建参数
Dim parameters As SqlParameter() = { _
New SqlParameter("@ProductId", SqlDbType.Int, 4)}
parameters(0).Value = productId
Dim products As SqlDataReader
Try
products = Me.ExecuteReader(ConnectionString, CommandType.StoredProcedure, "sp_Product_GetProductImage", parameters)
Return products
Finally
End Try
End Function
#End Region
---存储过程
ALTER PROCEDURE sp_Product_GetProductImage
@ProductID int
AS
Select ProductPicture from Product_First Where ProductID=@ProductID
RETURN
转载于:https://www.cnblogs.com/xzcastle/archive/2006/01/17/319105.html
最后
以上就是健忘枕头为你收集整理的单层体系结构到三层体系结构的转变的全部内容,希望文章能够帮你解决单层体系结构到三层体系结构的转变所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复