ASP.NET向SQL Server数据库添加图片 -张志
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> ADP及SQL SERVER


ASP.NET向SQL Server数据库添加图片

发表时间:2006/8/24 评论(0) 浏览(5738)  评论 | 加入收藏 | 复制
   
摘 要:ASP.NET向SQL Server数据库添加图片 
正 文:
aspx:
<%@ Page language="c#" Codebehind="Register.aspx.cs" AutoEventWireup="false" Inherits="shop.Register" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>注册</title>
</HEAD>
<body style="FONT-SIZE: 12px">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="50%" align="center" bgColor="beige"
border="0">
<TR>
<TD bgColor="#cccc66" colSpan="2" height="25" rowSpan="">添加新用户</TD>
</TR>
<TR>
<TD>姓名</TD>
<TD>
<asp:TextBox id="txtPersonName" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>电子邮件</TD>
<TD>
<asp:TextBox id="txtPersonEmail" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>性别</TD>
<TD>
<asp:RadioButton GroupName="sex" Text="男" ID="sexMale" Runat="server" />
<asp:RadioButton GroupName="sex" Text="女" ID="sexFeMale" Runat="server" />
</TD>
</TR>
<TR>
<TD>出生日期</TD>
<TD>
<asp:TextBox id="txtPersonDOB" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>照片</TD>
<TD><INPUT type="file" id="personImage" name="PersonImage" runat="server"></TD>
</TR>
<TR>
<TD align="center" colSpan="2">
<asp:Button id="Button1" onClick="AddPerson" runat="server" Text="添加"></asp:Button>
</TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
aspx.cs:
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace shop
{
/// <summary>
/// Register 的摘要说明。
/// </summary>
public class Register : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtPersonName;
protected System.Web.UI.WebControls.TextBox txtPersonEmail;
protected System.Web.UI.WebControls.RadioButton sexMale;
protected System.Web.UI.WebControls.RadioButton sexFeMale;
protected System.Web.UI.WebControls.TextBox txtPersonDOB;
protected System.Web.UI.HtmlControls.HtmlInputFile personImage;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
public void AddPerson(object sender, System.EventArgs e)
{
int intImageSize;
string strImageType;
Stream ImageStream;
intImageSize = personImage.PostedFile.ContentLength; // 文件大小
strImageType = personImage.PostedFile.ContentType; // 文件类型
ImageStream = personImage.PostedFile.InputStream;
byte[] ImageContent = new byte[intImageSize];


Access软件网交流QQ群(群号:198465573)
 
 相关文章
向SQL Server数据库添加图片  【umvsoft整理  2008/8/8】
[示例]添加图片示例  【jingyu  2010/1/9】
用access向EXCEL的Image控件中添加图片  【zealwoo  2010/9/8】
【Listview教程05】添加图片到列标题  【纵云梯  2012/5/26】
快速开发平台--通用附件管理/上传下载/添加图片附件的示例  【风行  2014/10/11】
常见问答
技术分类
相关资源
文章搜索
关于作者

张志

文章分类

文章存档

友情链接