All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
asp.net2.0生成验证码,并显示验证码_[Asp.Net教程]
ASP.NET,2.0角色及成员管理_[Asp.Net教程]
SQL jdbc解决自动自动增长列统一处理问题纪实_[SQL Server教程]
SQL循序渐进(7)更新记录_[SQL,Server教程]
Asp.Net,Ajax,学习笔记16,Profile,Service扩展方式_[Asp.Net教程]
ASP.NET2.0:使用GridView绑定XmlDocument对象_[Asp.Net教程]
最近收集的有用的Javscript小技巧_JavaScript技术_编程技术
Winform中在Form上截取消息的两种方法_[Asp.Net教程]
.Net中使用GDI+提高gif图片画质的代码_[Asp.Net教程]
如何用VS2005制作Web安装程序_[Asp.Net教程]
Reading number is top 10 pictures
The money of more than 100 countries and regions6
再来随便发几张
治疗多发性骨髓瘤的特效药,一万二一支
到南昌西站了3
NeedWallpaper14
Ashlynn Brooke a group sexy photo1
The world's top ten most beautiful railway station2
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
2012 national geographic daily picture2
PengLiYuan lady for the world health organization fight TB and AIDS goodwill ambassador
Download software ranking
实战黑客不求人
Rio big adventure
dreamweaver8中文版
WebService在.NET中的实战应用教学视频 → 第1集
Take off clothes to survival
Unix video tutorial6
Love the forty days
Wild things 2
Tram sex maniac 2 (H) rar bag9
Sora aoi, the nurse, uniform ,nursing assistant
delv published in(发表于) 2014/1/23 2:55:51 Edit(编辑)
asp.net,将文字内容和图片插入到Access_[Asp.Net教程]

asp.net,将文字内容和图片插入到Access_[Asp.Net教程]

asp.net 将文字内容和图片插入到Access_[Asp.Net教程]

Image2Access.aspx

<%@ Page language="c#" Debug="true" Codebehind="Image2Access.aspx.cs"
AutoEventWireup="false" Inherits="eMeng.Exam.Image2Access" %>



上传文件到 Access 数据库







asp.net 上传文件到 Access 数据库


HeaderStyle-Font-Bold="True" HeaderStyle-ForeColor="#ffffff" ItemStyle-BackColor="Beige" BorderColor="#000000"
Runat="server" HeaderStyle-HorizontalAlign="Center">


















ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %>' />




文件名字:


文件:









Image2Access.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.IO;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace eMeng.Exam
{
///
/// Image2Access 的摘要说明。
///

public class Image2Access : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText MyFileName;
protected System.Web.UI.HtmlControls.HtmlInputFile MyFile;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
protected System.Web.UI.WebControls.DataGrid DG_Persons;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
BindGrid();
}
private void BindGrid()
{
string strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ Server.MapPath("Image2Access.mdb");
OleDbConnection myConnection = new OleDbConnection(strCnn);
OleDbCommand myCommand = new OleDbCommand("Select * FROM Person", myConnection);
myCommand.CommandType = CommandType.Text;
try
{
myConnection.Open();
DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DG_Persons.DataBind();
}
catch(OleDbException SQLexc)
{
Response.Write("提取数据时出现错误:" + SQLexc.ToString());
}
}
protected string FormatURL(object strArgument)
{
return "ReadImage.aspx?id=" + strArgument.ToString();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///

private void InitializeComponent()
{
this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Submit1_ServerClick(object sender, System.EventArgs e)
{
//得到提交的文件
Stream fileDataStream = MyFile.PostedFile.InputStream;

//得到文件大小
int fileLength = MyFile.PostedFile.ContentLength;

//创建数组
byte[] fileData = new byte[fileLength];

//把文件流填充到数组
fileDataStream.Read(fileData,0,fileLength);

//得到文件名字
string fileTitle = MyFileName.Value;

//得到文件类型
string fileType = MyFile.PostedFile.ContentType;

//构建数据库连接,SQL语句,创建参数
string strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Image2Access.mdb");
OleDbConnection myConnection = new OleDbConnection(strCnn);
OleDbCommand command = new OleDbCommand ("Insert INTO Person (PersonName,PersonEmail,PersonSex,PersonImageType,PersonImage)" +
"VALUES (@PersonName,@PersonEmail,@PersonSex,@PersonImageType,@PersonImage)", myConnection);

System.Data.OleDb.OleDbParameter paramPersonName = new OleDbParameter("@PersonName", System.Data.OleDb.OleDbType.VarChar,50);
paramPersonName.Value = fileTitle;
command.Parameters.Add(paramPersonName);

System.Data.OleDb.OleDbParameter paramPersonEmail = new OleDbParameter("@PersonEmail", System.Data.OleDb.OleDbType.VarChar,50);
paramPersonEmail.Value = "mengxianhui@dotnet.aspx.cc";
command.Parameters.Add(paramPersonEmail);

System.Data.OleDb.OleDbParameter paramPersonSex = new OleDbParameter("@paramPersonSex", System.Data.OleDb.OleDbType.VarChar,50);
paramPersonSex.Value = "男";
command.Parameters.Add(paramPersonSex);

System.Data.OleDb.OleDbParameter paramPersonImageType = new OleDbParameter("@PersonImageType", System.Data.OleDb.OleDbType.VarChar,50);
paramPersonImageType.Value = fileType;
command.Parameters.Add(paramPersonImageType);

System.Data.OleDb.OleDbParameter paramPersonImage = new OleDbParameter("@PersonImage", System.Data.OleDb.OleDbType.Binary);
paramPersonImage.Value = fileData;
command.Parameters.Add(paramPersonImage);

//打开连接,执行查询
myConnection.Open();
command.ExecuteNonQuery();
myConnection.Close();

}
}
}






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.