上傳圖片后使用數(shù)據(jù)庫保存圖片的示例分享
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讀取被點(diǎn)擊次數(shù)的簡單實例(從數(shù)據(jù)庫中讀取)
- sql server 2008數(shù)據(jù)庫連接字符串大全
- openfiledialog讀取txt寫入數(shù)據(jù)庫示例
- sql2000數(shù)據(jù)庫清除重復(fù)數(shù)據(jù)的二種方法
- linux數(shù)據(jù)庫備份并通過ftp上傳腳本分享
- java使用jdbc操作數(shù)據(jù)庫示例分享
- MySQL數(shù)據(jù)庫命名規(guī)范及約定
- net操作access數(shù)據(jù)庫示例分享
- mysql跨數(shù)據(jù)庫復(fù)制表(在同一IP地址中)示例
- Drupal7連接多個數(shù)據(jù)庫及常見問題解決
- Drupal讀取Excel并導(dǎo)入數(shù)據(jù)庫實例
- sqlserver備份還原數(shù)據(jù)庫功能封裝分享
- Drupal7中常用的數(shù)據(jù)庫操作實例
- android通過jxl讀excel存入sqlite3數(shù)據(jù)庫
- java自定義動態(tài)鏈接數(shù)據(jù)庫示例
- php把session寫入數(shù)據(jù)庫示例
- 在linux中導(dǎo)入sql文件的方法分享(使用命令行轉(zhuǎn)移mysql數(shù)據(jù)庫)
- 四種數(shù)據(jù)庫隨機(jī)獲取10條數(shù)據(jù)的方法
相關(guān)文章
淺談ASP.NET Core 中jwt授權(quán)認(rèn)證的流程原理
這篇文章主要介紹了淺談ASP.NET Core 中jwt授權(quán)認(rèn)證的流程原理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03.NET性能調(diào)優(yōu)之一:ANTS Performance Profiler的使用介紹
本系列文章主要會介紹一些.NET性能調(diào)優(yōu)的工具、Web性能優(yōu)化的規(guī)則(如YSlow)及方法等等內(nèi)容。成文前最不希望看到的就是園子里不間斷的“哪個語言好,哪個語言性能高”的爭論,不多說,真正的明白人都應(yīng)該知道這樣的爭論有沒有意義,希望我們能從實際性能優(yōu)化的角度去討論問題2013-01-01ASP.NET 2.0下隨機(jī)讀取Access記錄的實現(xiàn)方法
ASP.NET 2.0下隨機(jī)讀取Access記錄的實現(xiàn)方法...2007-03-03