下面是个C#向ACCESS数据库插入图片教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!
【 tulaoshi.com - 编程语言 】
精华网络内容 :http://www.qqread.com/network/
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)%@ Page language="c#" Debug="true" Codebehind="Image2Access.aspx.cs" AutoEventWireup="false" Inherits="eMeng.Exam.Image2Access" %
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
HTML
HEAD
title上传文件到 Access 数据库/title
meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"
meta name="CODE_LANGUAGE" Content="C#"
meta name="vs_defaultClientScript" content="JavaScript"
meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"
/HEAD
body MS_POSITIONING="GridLayout"
form id="DataGridShowImage" method="post" runat="server" enctype="multipart/form-data"
h3 align="center"上传文件到 Access 数据库/h3
asp:DataGrid ID="DG_Persons" AutoGenerateColumns="False" Width="99%" HeaderStyle-BackColor="#ff0000"
HeaderStyle-Font-Bold="True" HeaderStyle-ForeColor="#ffffff" ItemStyle-BackColor="Beige" BorderColor="#000000"
Runat="server" HeaderStyle-HorizontalAlign="Center"
Columns
asp:TemplateColumn HeaderText="姓名"
ItemTemplate
asp:Label Runat="server" Text='%# DataBinder.Eval(Container.DataItem, "PersonName") %' ID="Label1"/
/ItemTemplate
/asp:TemplateColumn
asp:TemplateColumn HeaderText="电子邮件"
ItemTemplate
asp:Label Runat="server" Text='%# DataBinder.Eval(Container.DataItem, "PersonEmail") %' ID="Label2"/
/ItemTemplate
/asp:TemplateColumn
asp:TemplateColumn HeaderText="性别"
ItemTemplate
asp:Label Runat="server" Text='%# DataBinder.Eval(Container.DataItem, "PersonSex") %' ID="Label3"/
/ItemTemplate
/asp:TemplateColumn
asp:TemplateColumn HeaderText="照片"
ItemTemplate
asp:Image Runat=server ID="Image1" ImageUrl='%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %' /
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:DataGrid
b文件名字:/binput id="MyFileName" type="text" runat="server" NAME="MyFileName"
P
b文件:/binput id="MyFile" type="file" runat="server" NAME="MyFile"
br
br
input type="submit" value="开始上传" runat="server" ID="Submit1" NAME="Submit1"
/P
/form
/body
/HTML
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
{
/// summary
/// Image2Access 的摘要说明。
/// /summary
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();
}
来源:http://www.tulaoshi.com/n/20160219/1617360.html
看过《C#向ACCESS数据库插入图片》的人还看了以下文章 更多>>