0
A
回答
1
比方說你有aspx頁面:
<input id="File1" type="file" runat="server"/>
<asp:Button ID="OnUpload" runat="server" Text="Upload" />
而在VB頁
Protected Sub OnUpload_Click(sender As Object, e As EventArgs) Handles OnUpload.Click
' Create a byte[] from the input file
Dim len As Integer = File1.PostedFile.ContentLength
Dim pic As Byte() = New Byte(len - 1) {}
File1.PostedFile.InputStream.Read(pic, 0, len)
' Insert the image and comment into the database
Dim connection As New SqlConnection("server=localhost;database=gallery;uid=yourusername;pwd=yourpassword")
Try
connection.Open()
Dim cmd As New SqlCommand("insert into Image " & "(Picture) values (@image)", connection)
cmd.Parameters.Add("@image", SqlDbType.Image, pic.Length).Value = pic
cmd.ExecuteNonQuery()
Finally
connection.Close()
End Try
End Sub
要插入一個圖像到SQL Server首先確認圖像被添加到的列的數據類型是圖像數據類型。
試試看......
而且你可以在這裏找到一些例子: http://infynet.wordpress.com/2010/09/29/store-image-in-sql-database-using-vb-net/
在另一方面,它不建議保存圖片在數據庫中,數據庫會變成巨大沒有時間和備份和恢復將變成不可能的。
0
是的......這是可能的!
將圖像設置爲圖片框後,即可以相同的方式檢索圖像。
Image img = myPictureBox.Image
現在拍攝該圖像並將其保存在數據庫中或將其保存在硬盤中並保存在數據庫中的文件路徑。
相關問題
- 1. 如何顯示/從Access數據庫獲取圖像到圖片框在VB
- 2. 試圖分配圖片到VB中的圖片框
- 3. 試圖插入到數據庫與MainActivity從片段與片段
- 4. 在圖片框中插入圖標
- 5. 批量插入圖片到SQL Server數據庫
- 6. 如何在jsp和hibernate數據庫中插入圖片url?
- 7. 如何在Sqlite數據庫中插入圖片?
- 8. 圖片框從文件到BLOB到SQL Server數據庫,然後從數據庫到圖片框
- 9. VB.net - 從MySQL插入/檢索圖片數據庫直接進入/從一個Picturebox
- 10. PHP/SQL圖片上傳到數據庫
- 11. 上傳圖片並直接插入到CKEditor中
- 12. 在yahoo郵箱中插入邊框顏色到圖片鏈接
- 13. 自動圖片庫插入
- 14. 從url中插入圖片到數據庫
- 15. 如何將SharePoint元數據(圖片)插入到Word文檔中?
- 16. 如何在將圖片插入Android圖庫時更改圖片的名稱?
- 17. SQL數據庫中的圖片
- 18. 插入圖片
- 19. 在android中插入圖片
- 20. 如何將圖片鏈接到MySQL數據庫中的用戶?
- 21. 從c#winforms中的數據庫檢索圖像到圖片框
- 22. 當直接瀏覽圖片時將圖片應用於圖片
- 23. 通過直接輸入圖片網址來上傳圖片?
- 24. 將圖片插入餅圖切片
- 25. Winforms:如何上傳圖片到SQL Server數據庫使用C#
- 26. 如何將圖片從圖片庫轉換爲位圖圖片以插入到另一個圖片庫中的視覺基本
- 27. 圖片圖片框
- 28. 在表格視圖中插入圖片?
- 29. 當我嘗試插入圖片從數據庫到控制 - 我得到保存圖片在磁盤
- 30. 如何打開圖庫並通過點擊圖像直接選擇圖片到Adobe圖片編輯器?
標題和實際問題似乎相互矛盾......請詳細說明你想要做什麼:圖片來自哪裏,你想要做什麼以及你想要存儲在哪裏? – Treb 2012-03-07 07:49:52
由於性能的原因,我將圖像保存到數據庫中是個好主意。但是,在這裏你可以找到http://stackoverflow.com/questions/416881/insert-picture-into-sql-server-2005-image-field-using-only-sql – 2012-03-07 07:50:08
我想存儲在.mdf中的圖像存在於圖片框中的文件。但是我想在沒有FileInfo的幫助下做到這一點。 – Dev 2012-03-07 07:56:47