[.NET] 圖片存入ACCESS及讀取問題
應用程式專案
發完文才發現有DB版 不過這一篇應該較偏程式...吧
如果有錯也請通知我一下 謝謝
最近在做一個菜單的資料庫程式
想要讓他能有存入、修改、刪除、讀取的功能
目前是用 存圖片路徑 的方法
程式碼如下
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ToolStripButton1.Click
OpenFileDialog1.Filter = "圖檔|*.jpg;*.gif;*.jpeg;g;|所有檔案|*.*"
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
PictureBox1.Image = New Bitmap(OpenFileDialog1.FileName)
`先用OpenFileDialog去選擇圖片 再用一個PictureBox顯示所選的圖片
Dim testFile As System.IO.FileInfo
testFile = My.Computer.FileSystem.GetFileInfo(OpenFileDialog1.FileName)
Dim folderPath As String = testFile.DirectoryName
Dim fileName As String = testFile.Name
Dim fullPath As String
fullPath = My.Computer.FileSystem.CombinePath(folderPath,fileName)
PictureBox1.ImageLocation = fullPath
`將圖片的路徑存成PictureBox1.ImageLocation 再把它存入資料庫
End If
End Sub
上面的程式碼測試過是能用的 能把圖檔路徑存入資料庫
而我的問題就在接下來
如何讓程式讀路徑並顯示圖片在某個PictureBox中呢??
我是希望能做到
`下面是 DataGridView
菜式名稱 價格 卡路里
豬排 80 200
牛排 100 300
雞排 100 300
然後點擊 DataGridView 中的豬排 圖片就能顯示在某個 PictureBox 中
點擊牛排就能顯示牛排的圖片
寫到這才發現變成兩個問題了...
如何判定滑鼠選取了哪一筆資料???
如何從資料庫中讀取某筆資料的圖檔路徑 並以圖片方式顯示在 PictureBox 中呢???
還請各位不吝指教
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.237.224.18
※ 編輯: flirmnave 來自: 36.237.224.18 (12/31 01:35)
→
12/31 14:50, , 1F
12/31 14:50, 1F
→
12/31 14:51, , 2F
12/31 14:51, 2F
→
12/31 14:51, , 3F
12/31 14:51, 3F
ㄜ 那一行我是用來取圖片路徑並準備存入資料庫的
但我不曉得如何從資料庫的欄位讀出路徑並顯示圖片在PictureBox中
RowCommand 正在研究
雖然很不好意思 但目前手邊沒有書籍可供參考
網路上搜尋到的大多都是VB6的範例
雖然有.NET的說明 但寫的不是很清楚
能不能請各位給予更詳細的指導
不情之請 麻煩各位了
※ 編輯: flirmnave 來自: 36.237.224.18 (12/31 17:50)
→
01/01 03:16, , 4F
01/01 03:16, 4F
→
01/01 03:17, , 5F
01/01 03:17, 5F
→
01/01 03:17, , 6F
01/01 03:17, 6F
→
01/02 13:07, , 7F
01/02 13:07, 7F