全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1652
推到 Plurk!
推到 Facebook!

(D2005)煩請各位高手幫忙有關圖檔上傳至資料庫的問題,感恩!!

尚未結案
robbiehsieh
一般會員


發表:1
回覆:0
積分:0
註冊:2005-08-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-01 16:08:48 IP:211.20.xxx.xxx 未訂閱
小弟一直碰到字串或二進位資料會被截斷的問題,由該訊息可以確定是要存入的檔案太大無法存入資料庫內,但小弟在資料庫(SQL 2000)內用的是varbinary, 欄位大小為50,先前用image,內定欄位大小為16無法更改也會出現相同情況,所以小弟相信應該是程式碼的問題.應該不是檔案太大的問題.我也上傳大概幾十K的圖檔怎會不夠大呢?可否煩請各位高手指點迷津,小弟感激不盡. 程式碼如下: procedure TWebForm3.btupload_Click(sender: System.Object; e: System.EventArgs); var UpFile: HttpPostedFile; ImageStream: Stream; FileLength: Integer; strSQL: String; Buffer1: TByteDynArray; begin //make sure the client selected an existing file UpFile := file1.PostedFile; if UpFile.ContentLength <> 0 then begin ImageStream := UpFile.InputStream; FileLength := UpFile.ContentLength; setlength(Buffer1,Filelength); ImageStream.Read(Buffer1,0,FileLength); ImageStream.Close; strSQL := 'insert into imgtest(imgfile, imgtype) values(@imgfile,@imgtype)'; cmd.CommandText := strSQL; cmd.Parameters.Add('@imgfile',SqlDbType.VarBinary); cmd.Parameters.Add('@imgtype',SqlDbType.Char,20); if ( not page.IsReusable ) then begin cn.Open; cmd.Parameters.Item['@imgfile'].Value := Buffer1; cmd.Parameters.Item['@imgtype'].Value := Upfile.ContentType; cmd.ExecuteNonQuery; <------ 錯誤出現 //在請問各位一下,若要即時將圖片顯示出來可以用以下方式嗎? image1.ImageUrl := UpFile.FileName; image1.DataBind; cn.Close; end; end; end;
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-02 19:20:04 IP:211.22.xxx.xxx 未訂閱
雖然你用的是Delphi 2005但是應該與Delphi 7,相去不遠吧!如果是請使用TBLOBStream這個類別來操作圖形存入SQL 2000的動作。 看下面的站內討論,或者搜尋TBLOBStream有更多的資料: http://delphi.ktop.com.tw/topic.php?topic_id=48855 http://delphi.ktop.com.tw/topic.php?topic_id=44990 ---------------------------------------------- We will either find a way, or make one. -Hannibal -。
系統時間:2024-05-14 18:46:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!