<p>准备工作:</p>

 假设上传界面仅有一个字段,即图片。那么后台将该图片存储到数据库中去的处理代码示例如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
    Option Explicit
    
    Session.CodePage = 65001
%>
<!--#include file="../ClassModule/CFormDataGetter.asp"-->
<!--#include file="../ClassModule/CImage.asp"-->
<!--#include file="../ClassModule/CDatabase.asp"-->

<% Dim form, image Set form = New CFormDataGetter Set image = New CImage

If form.FormSize &gt; 0 Then    
    image.CFile2Image form.GetFile("image")
    
    Response.Write "&lt;p&gt;image.ImageType = " &amp; image.ImageType &amp; "&lt;/p&gt;"
    Response.Write "&lt;p&gt;image.ImageVersion = " &amp; image.ImageVersion &amp; "&lt;/p&gt;"
    Response.Write "&lt;p&gt;image.ImageWidth = " &amp; image.ImageWidth &amp; "&lt;/p&gt;"
    
    Dim db, lState, sInfo    
    Const sDBUID = ""
    Const sDBPWD = ""

    
    Set db = New CDatabase    
    
    lState = db.Connect2Access(Server.MapPath("MyDeskCity.mdb"), sDBUID, sDBPWD)
    If lState = 0 Then
        Response.Write "数据库连接失败!"
    Else
        ' 存储图片到数据库
        Dim cmd, sSQL
        sSQL = "Insert Into MyDeskCity (Image, ImageWidth, ImageHeight, ImageType) Values (?, " &amp; Clng(image.ImageWidth) &amp; ", " &amp; CLng(image.ImageHeight) &amp; ", '" &amp; image.ImageType &amp; "')"
        Set cmd = Server.CreateObject("ADODB.Command")
        cmd.ActiveConnection = db.oConn
        cmd.CommandText = sSQL
        
        cmd.Parameters.Append cmd.CreateParameter("@Image", 205, 1, image.Size)
        cmd("@Image").AppendChunk image.BinaryStream
        
        cmd.Execute
    End If
    
    db.Disconnect
    Set db = Nothing

    If Err.Number = 0 Then
        sInfo = "上传图片成功!"
    Else
        sInfo = "上传图片失败!"
    End If
Else
    sInfo = "没有选择图片"
End If

Session("ssnsInfo") = sInfo
Response.Redirect Request.ServerVariables("HTTP_REFERER")

%>