Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > ADP及SQL SERVER

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

时 间:2006-08-24 00:00:00
作 者:UMVsoft整理   ID:8  城市:上海  QQ:2851379730点击这里给张志发消息
摘 要: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群 (群号:54525238)       Access源码网店


常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助