如果是图片的话可以这样
getimg.asp:
<%
Response.Expires =0
Response.Buffer =true
Response.Clear
Response.ContentType="image/gif"
sql="select fileName,fileDesc,filecontent from fileattachment where id='"&request("id")&"' "
set rs=conn1.execute(sql)
Response.BinaryWrite rs("filecontent")
rs.close
Response.End
%>
另一个文件用来显示
<img src="getimg.asp?id=<%=id%>" width="100" height="100">可执行文件的话需要下载执行

解决方案 »

  1.   

    这段代码,可以在网页上传任何文件(图像,doc..)到数据库,
    你可以参考一下,有时间再和你多聊一下
    public void myInsert()
    {
    Int32 intFileLength;
    string strFileType;
    string strFileName;
    Stream stmFile;
    strFileName="";
    strFileName=FileBox1.PostedFile.FileName;
    intFileLength=FileBox1.PostedFile.ContentLength;
    strFileType=FileBox1.PostedFile.ContentType;
    //strFileType="dd";
    stmFile=FileBox1.PostedFile.InputStream;
    byte[] ByteFile=new byte[intFileLength];
    stmFile.Read(ByteFile,0,intFileLength);
    /*
    FileStream fs = new FileStream("aa.doc", FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    byte[] DocByte = br.ReadBytes((int)fs.Length);
    fs.Close();
    */
    SqlConnection myCon=new SqlConnection("server=(local);database=test;uid=sa;pwd=");
    string strCom="INSERT INTO FileByField Values(@Name,@FileData,@FileType,@FileLength)";
    SqlCommand myCom=new SqlCommand(strCom,myCon);
    myCom.Parameters.Add("@Name",SqlDbType.Char,255);
    myCom.Parameters.Add("@FileData",SqlDbType.Image);
    myCom.Parameters.Add("@FileType",SqlDbType.Char,255);
    myCom.Parameters.Add("@FileLength",SqlDbType.BigInt);

    myCom.Parameters["@Name"].Value=strFileName;
    myCom.Parameters["@FileData"].Value=ByteFile;
    myCom.Parameters["@FileType"].Value=strFileType;
    myCom.Parameters["@FileLength"].Value=intFileLength;
    myCon.Open();
    try
    { myCom.ExecuteNonQuery(); }
    catch(SqlException e)
    {
    if(e.Number==2627)
    Response.Write("PrimaryKey Error");
    else
    Response.Write("Other Error");
    }
    myCon.Close();
    BindData();
    }