主题:上传图片并插入到数据库
独自等待
[专家分:0] 发布于 2006-04-08 23:50:00
怎么上传图片到数据库,然后在从数据库里调出来啊.急急
回复列表 (共3个回复)
沙发
hahaguai [专家分:80] 发布于 2006-04-10 10:38:00
偶也想要
哪位高手指点一下
板凳
au99mdyy [专家分:20] 发布于 2006-04-10 22:56:00
string fullfilename=this.upfile.PostedFile.FileName;
string filename=fullfilename.Substring(fullfilename.LastIndexOf("\\")+1);
string type=fullfilename.Substring(fullfilename.LastIndexOf(".")+1);
if(type=="jpg"||type=="dmp"||type=="gif")
{
this.upfile.PostedFile.SaveAs(Server.MapPath("upfiles")+"\\"+filename);
}
else
{
Response.Write("<script language='javascript'>alert('你上传的图片格式错误!')</script>");
}
3 楼
大海兄 [专家分:50] 发布于 2006-05-13 08:33:00
这是图片的显示:
imageread.aspx:
<%@ Page Language="VB" Src ="imageread.aspx.vb" Inherits="imageread" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>图片显示</title>
</head>
<body>
<form id="form1" method ="post" runat="server">
<div>
<asp:Button ID="btnShow" runat="server" OnClick ="btnShow_Click" Text="显示图片" />
<asp:Label ID="lblType" runat="server" Text="Label" Width="80px"></asp:Label></div>
</form>
</body>
</html>
imageread.aspx.vb:
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Public Class imageread
Inherits System.Web.UI.Page
Protected lblType As Label
Sub Page_Load()
End Sub
Sub btnShow_Click(ByVal s As Object, ByVal e As EventArgs)
Dim consql As SqlConnection
Dim cmdsql As SqlCommand
Dim dtrsql As SqlDataReader
Dim strsql As String
consql = New SqlConnection("Server=localhost;uid=sa;pwd=;database=同学录")
strsql = "Select * From images Where ID=2"
cmdsql = New SqlCommand(strsql, consql)
Try
consql.Open()
dtrsql = cmdsql.ExecuteReader
While dtrsql.Read
Response.ContentType = dtrsql("imgType")
lblType.Text = dtrsql("imgName")
Response.OutputStream.Write(dtrsql("imgContent"), 0, dtrsql("imgLength"))
End While
Response.End()
dtrsql.Close()
consql.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Class
我来回复