.net中把图片上传到数据库
来源:百度知道 编辑:UC知道 时间:2024/05/23 17:57:30
//上传文件:upload.aspx
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
public void AddPerson(object sender, EventArgs e)
{
Int64 intImageSize;
string strImageType;
Stream ImageStream ;
intImageSize = PersonImage.PostedFile.ContentLength;
strImageType = PersonImage.PostedFile.ContentType;
ImageStream = PersonImage.PostedFile.InputStream;
Byte[] ImageContent = new Byte[intImageSize];
int intStatus= ImageStream.Read(ImageContent,0,PersonImage.PostedFile.ContentLength);
OleDbConnection MyConnection = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" Server.MapPath("ps.mdb"));
OleDbCommand MyCommand = new OleDbCommand("INSERT I