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

Reading number is top 10 articles
初学:在PHP开发中如何使用Session?_php资料_编程技术
C#中GDI+变形的矩阵表示形式
多文件上传Asp.net(C#)_[Asp.Net教程]
Sql Server 2005 数据库维护计划_[SQL Server教程]
初学认识:javascript和Java是两个完全不同的语言_JavaScript技术_编程技术
Linux操作系统中用PHP构建网站详解_php资料_编程技术
在Visual,C#中定义和使用自己的特性_.net资料_编程技术
通过PHP和Sajax使用Ajax之javascript_php资料_编程技术
JS代码的格式化和压缩_JavaScript技术_编程技术
在Win2003,R2上安装SQL,Server,2005(二)_mssql学习_编程技术
Reading number is top 10 pictures
青春清纯美女大集合2
Female model behind the bitterness, often being overcharged1
看到这名字我也是醉了。。。。。。
教你做读书笔记
Summer is most suitable for young people to travel in China8
Beautiful Japanese beauty(漂亮的日本美女)3
NeedWallpaper12
农夫山泉变身记
NeedWallpaper13
Sora aoi mirror memorial classics4
Download software ranking
Unix video tutorial20
网页特效实例大全
Sora aoi's film--cangkong_Blue.Sky
传奇私服架设教程
Tram sex maniac 2 (H) rar bag2
中国结婚习俗实录
传奇私服架设教程-chm
Sora aoi - one of more PK
Tram sex maniac 2 (H) rar bag3
VC++6.0简体中文版
delv published in(发表于) 2014/1/23 3:12:50 Edit(编辑)
C#向ACCESS数据库插入图片_[Asp.Net教程]

C#向ACCESS数据库插入图片_[Asp.Net教程]

C#向ACCESS数据库插入图片_[Asp.Net教程]

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



上传文件到 Access 数据库







上传文件到 Access 数据库


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























文件名字:


文件:










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 窗体设计器生成的代码 http://sucai.knowsky.com/
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.