上传图片后使用数据库保存图片的示例分享
HttpPostedFile UpFile = File1.PostedFile;
int FileLenght = UpFile.ContentLength;
decimal FileSize = FileLenght / 1024;
if (FileLenght == 0)
{
DIVShowGVError.Visible = true;
LblShowGVError.Text = "请选择上传文件";
return;
}
string strImageName = UpFile.FileName;
string strImageType = strImageName.Substring(strImageName.LastIndexOf(".")).ToLower();
if (strImageType != ".jpg" && strImageType != ".jpeg" && strImageType != ".bmp" && strImageType != ".png")
{
DIVShowGVError.Visible = true;
LblShowGVError.Text = "請上傳以下文件格式的圖片:jpg,jpeg,bmp,png";
return;
}
if (FileSize > 2048)
{
DIVShowGVError.Visible = true;
LblShowGVError.Text = "上傳圖片不能大於2M";
return;
}
else
{
Byte[] FileByteArray = new Byte[FileLenght];
Stream StreamObject = UpFile.InputStream;
StreamObject.Read(FileByteArray, 0, FileLenght);
strNewLeave = "insert into [Leave]([ID],[EmployeeNo],[AgentID],[LeaveType],[StartDate],[EndDate],[Hours],[LeaveReason],[ReportTime],[ReportID],[ImageName],[ImageData]) ";
strNewLeave += "values(@LeaveNo,@EmpNo,@AgentName,@LeaType,@StartDate,@EndDate,@Hours,@Reason,getdate(),@Admin,@ImageName,@Image) ";
sqlPara = new SqlParameter[] {
new SqlParameter("@LeaveNo",strLeaNo),
new SqlParameter("@EmpNo",strEmpNo),
new SqlParameter("@AgentName",strAgentID),
new SqlParameter("@LeaType",strLeaType),
new SqlParameter("@StartDate",strDateSt),
new SqlParameter("@EndDate",strDateEnd),
new SqlParameter("@Hours",strHours),
new SqlParameter("@Reason",strReason),
new SqlParameter("@Admin",strAdmin),
new SqlParameter("@ImageName",strImageName),
new SqlParameter("@Image",FileByteArray)
};
StreamObject.Close();
}
SQLHelper sqlH = new SQLHelper();
string strID = context.Request["ID"];
byte[] MyData = new byte[0];
string str = " select [ImageData] from [Leave] where [ID]='" + strID + "' ";
DataTable dt = sqlH.ExecuteQuery(str, CommandType.Text);
if (dt.Rows.Count > 0)
{
MyData = (byte[])dt.Rows[0][0];
int ArraySize = MyData.GetUpperBound(0);
context.Response.OutputStream.Write(MyData, 0, ArraySize);
}
- js读取被点击次数的简单实例(从数据库中读取)
- sql server 2008数据库连接字符串大全
- openfiledialog读取txt写入数据库示例
- sql2000数据库清除重复数据的二种方法
- linux数据库备份并通过ftp上传脚本分享
- java使用jdbc操作数据库示例分享
- MySQL数据库命名规范及约定
- net操作access数据库示例分享
- mysql跨数据库复制表(在同一IP地址中)示例
- Drupal7连接多个数据库及常见问题解决
- Drupal读取Excel并导入数据库实例
- sqlserver备份还原数据库功能封装分享
- Drupal7中常用的数据库操作实例
- android通过jxl读excel存入sqlite3数据库
- java自定义动态链接数据库示例
- php把session写入数据库示例
- 在linux中导入sql文件的方法分享(使用命令行转移mysql数据库)
- 四种数据库随机获取10条数据的方法
相关文章
ASP.NET Core应用错误处理之三种呈现错误页面的方式
这篇文章主要给大家介绍了关于ASP.NET Core应用错误处理之三种呈现错误页面的方式的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-01-01灵活掌握asp.net中gridview控件的多种使用方法(上)
这篇文章向大家推荐如何灵活掌握asp.net中gridview控件的多种使用方法,感兴趣的小伙伴们可以参考一下2015-11-11VS2012/VS2013本地发布网站问题集锦(HTTP错误代码)
这篇文章主要为大家详细介绍了VS2012/VS2013本地发布网站遇到问题,HTTP错误代码的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-04-04.net Core 3.0 WebApi 创建Linux守护进程的方法
这篇文章主要介绍了.net Core 3.0 WebApi 创建Linux守护进程的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-03-03使用Visual Studio创建ASP.NET Web API项目
这篇文章介绍了使用Visual Studio创建ASP.NET Web API项目的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-03-03
最新评论