日期:2013-10-20  浏览次数:20443 次

//上传文件: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 INTO manhua(img,biaoti,laiyuan,author,keyword,content) values(@img,@biaoti,@laiyuan,@author,@keyword,@content)", MyConnection);

MyCommand.Parameters.Add("@img",ImageContent);
MyCommand.Parameters.Add("@biaoti",txtname.Text);
MyCommand.Parameters.Add("@laiyuan",TextBox1.Text);
MyCommand.Parameters.Add("@author",TextBox2.Text);
MyCommand.Parameters.Add("@keyword",TextBox3.Text);
MyCommand.Parameters.Add("@content",TextBox4.Text);
try
{
MyConnection.Open();
MyCommand.ExecuteNonQuery();
MyConnection.Close();
//Response.Write("<font color="red">new person successfully added!</font>");
}
catch(OleDbException ex)
{
Response.Write("Insert Failed.Error Details are:" + ex.ToString());
}

txtname.Text="";
}

</script>
<html>
<head>
<title>Upload image to DB!</title>
</head>
<body style="FONT: 10pt verdana">
<form enctype="multipart/form-data" runat="server">
<table align="center">
<tbody>
<tr>
<td>
<font size="2">标  题:</font>
<asp:Textbox id="txtname" runat="server"></asp:Textbox>
</td>
</tr>
<tr>
<td>
<font size="2">来  源:</font>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<font size="2">作  者:</font>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<font size="2">关键字:</font>
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<font size="2">图