程式產生HTML格式內容存成 Excel檔名, 如果欄位中有01234的資料時Excel會將它視為數值
所以01234會變成1234, 所以要在此欄位前加上「 」即可保留文字型態的方式顯示。
例如 : 01234
2012年4月17日 星期二
2012年3月27日 星期二
圖片存入資料庫與檔案系統的優缺點比較
個人觀看了其它人的討論並記錄下來, 對於圖片存入資料庫與檔案系統的優缺點比較:
基本上我認為二者是可以結合的, 上傳存入資料庫的獨立圖表, 也存一份在檔案系統裡, 當要取圖時就去抓檔案系統的路徑圖片,如果找不到還可以去資料庫中讀取圖片或是重新生成圖片至指定的檔案系統裡,再次提供圖片讀取之用, 用途是圖片備份在資料庫裡, 目錄中的資料被刪了還有機會恢原, 不過這種雙機制在設計上會比較馬煩了一點但是可以取得很好的運作方式, 各取所長 ^^ 。
| 優點 | 缺點 | 適用性 | |
| 資料庫 | 方便管理,不會有路徑的問題發生,安全性較高 | 會加重資料庫的負擔,太多人讀取資料庫可能會掛掉 | 使用在小型圖片或是一些系統素材上, 系統架構顯示上會方便很多 |
| 檔案系統 | 讀取顯示效率佳 | 不方便管理,路徑位置設錯時常造成讀取失敗問題 | 適用在較大的圖片上,圖片目錄要設定只能讀取不能執行以防止木馬程式執行 |
基本上我認為二者是可以結合的, 上傳存入資料庫的獨立圖表, 也存一份在檔案系統裡, 當要取圖時就去抓檔案系統的路徑圖片,如果找不到還可以去資料庫中讀取圖片或是重新生成圖片至指定的檔案系統裡,再次提供圖片讀取之用, 用途是圖片備份在資料庫裡, 目錄中的資料被刪了還有機會恢原, 不過這種雙機制在設計上會比較馬煩了一點但是可以取得很好的運作方式, 各取所長 ^^ 。
2012年1月11日 星期三
ASP 判別回傳的rs是否沒有資料
ASP 判別回傳的rs是否沒有資料, 沒有就印出 "找不到任何資料"
if rs.eof and rs.bof then
response.write "找不到任何資料 <br>"
response.end
end if
Javascript 偵測到按下[Enter] 鍵時, 就送出表單
<script src="jquery-1.7.1.min.js" ></script> <script language=javascript> $(document).ready(function(){ $(document).keypress(function(event) { if ( event.which == 13 ) { $("#login").submit(); } }); }); </script>
2011年11月16日 星期三
ASP.NET C# 從資料庫(MSSQL)讀出圖檔
cmd.CommandText = "SELECT picture , filename FROM pic ";
SqlDataReader dr = cmd.ExecuteReader();
byte[] img = null;
while (dr.Read())
{
MyData data = new MyData();
img = (byte[]) dr["picture"];
MemoryStream str = new MemoryStream();
str.Write(img, 0, img.Length);
Bitmap bit = new Bitmap(str);
data.img = bit;
data.filename = (string) dr["filename"];
myDataList.Add(data);
}
ASP.NET C# 將檔圖存入資料庫(MSSQL)
// 讀取二進制檔
public byte[] ReadFile(string path)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(path);
long length = fInfo.Length;
FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)length);
return data;
}
// --讀取檔案轉成二進制字資料, 並存入資料庫裡--
imageData = ReadFile(k.ImageLocation);
// -- 新增資料的Sql語句 --
cmd.CommandText = "INSERT INTO pic ( filename, picture , in_time ) " +
" VALUES ( @imagePath, @imageData, @inTime ) ";
// --設定輸入參數--
cmd.Parameters.Add("@imagePath", SqlDbType.NVarChar).Value = k.Name;
cmd.Parameters.Add("@imageData", SqlDbType.Image).Value = imageData;
cmd.Parameters.Add("@inTime", SqlDbType.SmallDateTime).Value = DateTime.Now.Date;
// --設定輸入參數--
cmd.ExecuteNonQuery(); // 執行寫入作業
public byte[] ReadFile(string path)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(path);
long length = fInfo.Length;
FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)length);
return data;
}
// --讀取檔案轉成二進制字資料, 並存入資料庫裡--
imageData = ReadFile(k.ImageLocation);
// -- 新增資料的Sql語句 --
cmd.CommandText = "INSERT INTO pic ( filename, picture , in_time ) " +
" VALUES ( @imagePath, @imageData, @inTime ) ";
// --設定輸入參數--
cmd.Parameters.Add("@imagePath", SqlDbType.NVarChar).Value = k.Name;
cmd.Parameters.Add("@imageData", SqlDbType.Image).Value = imageData;
cmd.Parameters.Add("@inTime", SqlDbType.SmallDateTime).Value = DateTime.Now.Date;
// --設定輸入參數--
cmd.ExecuteNonQuery(); // 執行寫入作業
訂閱:
文章 (Atom)