📄 第六章 用户权限管理(六) -- c#读写数据库image字段_宪华_新浪博客.htm
字号:
<td><%=dr["orgname"]%>&nbsp;</td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td>出生日期</td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><%=dr["sbirthdate"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr
align="center"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td>职务(职责)</td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><%=dr["Business"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><FONT
face="宋体">家庭住址</FONT></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><%=dr["Address"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr
align="center"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><FONT
face="宋体">入职日期</FONT></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><%=dr["shiredate"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><FONT
face="宋体">家庭电话</FONT></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td
colSpan="2"><%=dr["HomePhone"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr
align="center"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td><FONT
face="宋体">手机号码</FONT></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td
colSpan="4"><%=dr["CellPhone"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR><tr
align="center"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td>员工简历</td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<td align="left" width="360" colSpan="4" style="RIGHT:50px;</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
WORD-BREAK:break-all;WORD-WRAP:break-word"><%=dr["Notes"]%></td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR>
</table><BR> <WBR> <WBR> <WBR> <WBR> <WBR>
<%<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
conn.Close();<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
else<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Response.Write("该用户信息不存在!");<BR> <WBR> <WBR> <WBR> <WBR> <WBR>
%><BR> <WBR> <WBR> <WBR> </form> <WBR></P>
<P align=left> <WBR> <WBR> <WBR>
<STRONG>EmployeeInfo.aspx.cs文件代码</STRONG>:</P>
<P align=left> <WBR> <WBR> <WBR> ......</P>
<P align=left> <WBR> <WBR> <WBR> using DataAccess;</P>
<P align=left> <WBR> <WBR> <WBR> namespace
workflow.admin<BR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>public
class EmployeeInfo :
System.Web.UI.Page<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>protected
SqlDataReader
dr=null;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
protected System.Web.UI.WebControls.Image
Image1;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
protected SqlConnection conn=null;</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
private void Page_Load(object sender, System.EventArgs
e)<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
if(Request.QueryString["id"] !=null & Request.QueryString["id"].ToString()
!="")<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
string
id=Request.QueryString["id"].ToString();<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
string strSql="select
EmployeeID,GroupID,EmployeeName,Sex,Business,CellPhone,</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
HomePhone,Address,Notes,sex_alias=(case Sex when 'M' then '男' else '女'</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
end),orgname=(select Group_Name from organization where</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>Group_ID=GroupID),shiredate=CONVERT(varchar(10),
HireDate, 120),</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
CONVERT(varchar(10), BirthDate, 120) <WBR> as sbirthdate from Employees</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
where
EmployeeID="+id;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Base basecode=new
Base();<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
dr=basecode.SQLExeDataReader(strSql);<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
conn=basecode.AppCon;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}</P>
<P align=left> <WBR> <WBR> <WBR> <WBR> <WBR>
}<BR> <WBR> <WBR> <WBR> }</P>
<P align=left> <WBR> <WBR> <WBR>
<STRONG>2、DisplayImage.aspx.cs文件代码</STRONG>:</P>
<P align=left> <WBR> <WBR> <WBR>
DisplayImage.aspx只有.Net自动生成的代码,照片的显示由DisplayImage.aspx.cs文件代码完成:</P>
<P align=left> <WBR> <WBR> <WBR> ......</P>
<P align=left> <WBR> <WBR> <WBR> using DataAccess;</P>
<P align=left> <WBR> <WBR> <WBR> namespace
workflow.admin<BR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR>public class
DisplayImage :
System.Web.UI.Page<BR> <WBR> <WBR> <WBR> <WBR> <WBR>
{ <WBR><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>private
void Page_Load(object sender, System.EventArgs
e)<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
if(!
IsPostBack)<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
//验证用户是否登录<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
if(Session["userid"] ==
null)<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Response.Redirect("./Message.aspx");<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>}<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>string
employeeID=Request.QueryString["id"];<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
string strSql="select Photo,PhotoImageType from Employees where</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
EmployeeID="+employeeID;<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Base basecode=new
Base();<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
SqlDataReader
dr=basecode.SQLExeDataReader(strSql);<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
dr.Read();<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
if((string)dr["PhotoImageType"]
!="")<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
{<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Response.ContentType=(string)dr["PhotoImageType"];<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Response.BinaryWrite((byte[])dr["Photo"]);<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
else<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
Response.Write("暂无照片");<BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
basecode.AppCon.Close();</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
}</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>}</P>
<P align=left> <WBR> <WBR> <WBR> }</P>
<P align=left> <WBR> <WBR> <WBR>
<STRONG>2、Employees.aspx文件代码</STRONG>:</P>
<P align=center><A
href="http://photo.blog.sina.com.cn/showpic.html#blogid=5f30147a0100dkmv&url=http://static14.photo.sina.com.cn/orignal/5f30147at67f8c3f84d4d"
target=_blank><IMG style="MAX-WIDTH: 500px"
src="第六章%20用户权限管理(六)%20--%20C%23读写数据库Image字段_宪华_新浪博客_files/5f30147at67f8c3f84d4d.jpg"></A></P>
<P align=center>图6.21 在属性生成器中设置控件列</P>
<P align=center> <WBR></P>
<P align=center><A
href="http://photo.blog.sina.com.cn/showpic.html#blogid=5f30147a0100dkmv&url=http://static6.photo.sina.com.cn/orignal/5f30147at67f95aa60425"
target=_blank><IMG style="MAX-WIDTH: 500px"
src="第六章%20用户权限管理(六)%20--%20C%23读写数据库Image字段_宪华_新浪博客_files/5f30147at67f95aa60425.gif"></A></P>
<P align=center>图6.22 编辑照片模板列</P>
<P align=left> <WBR> <WBR> <WBR> ......</P>
<P align=left> <WBR> <WBR> <WBR> <form id="Form1"
method="post" runat="server"></P>
<P align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <table
cellSpacing="0" cellPadding="0" width="100%" align="center"
border="0"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr><td style="FONT-SIZE: 16px"
align="center">员工管理数据表</td></tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr height="50"><td align="right"><span id="Message"
style="FONT-SIZE: 11pt;</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
FONT-FAMILY: Arial" runat="server"
MaintainState="false"></span>&nbsp;</td><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
</tr><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<tr><td></P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<asp:datagrid id="DataGrid1" runat="server" AllowPaging="True"</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>DataKeyField="EmployeeID"
Width="100%" HeaderStyle-HorizontalAlign="Center"</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<WBR>AutoGenerateColumns="False"
PageSize="8"><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<ItemStyle Font-Size="13px" HorizontalAlign="Center" Height="28px"</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
VerticalAlign="Bottom"></ItemStyle><BR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
<HeaderStyle Font-Size="16px" HorizontalAlign="Center" Height="30px"</P>
<P
align=left> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR> <WBR>
VerticalAlign="Middle"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -