當前位置:首頁 » 操作系統 » vb資料庫圖片

vb資料庫圖片

發布時間: 2023-08-11 22:31:12

『壹』 vb.net如何讀取oracle資料庫中的圖片

Public Sub Combo1_Click()

Dim adoCnn As ADODB.Connection

Dim rstOra As ADODB.Recordset

Dim intI As Integer

Set adoCnn = New ADODB.Connection

Set rstOra = New ADODB.Recordset

adoCnn.ConnectionString = "Provider=OraOLEDB.Oracle;User ID=dzjc;password=zlkj;Data Source=dzjc_2005;" '讀blob欄位要用Provider=OraOLEDB.Oracle

adoCnn.CursorLocation = adUseClient

adoCnn.Open

rstOra.CursorLocation = adUseClient

rstOra.ActiveConnection = adoCnn

rstOra.Open "SELECT zp FROM dzjc.dzjc_wfzp WHERE xh = '5'"

'Set Image1.DataSource = rstOra

Set Image1.Picture = PictureFromByteStream(rstOra.Fields("zp").Value)

End Sub

『貳』 VB+Access做資料庫如何保存圖片

access是微軟發布的一款關系型資料庫。access資料庫保存圖片的方法很多,可以通過vb,c++,php,asp等開發語言實現;也可以直接向access資料庫插入圖片進行保存。下面演示直接插入步驟:

1、打開access資料庫,新建一張數據表(存儲圖片的欄位類型選擇:OLE 對象);

6、這樣,一張圖片就保存到access資料庫里去了。

『叄』 vb如何將jpg圖片存入資料庫及其讀取方法

VB6 保存和讀取圖片到資料庫

dim stm as ADODB.Stream
dim rs as ADODB.Recordset
sub SavePictureToDB(cn As ADODB.Connection)
'將圖片存入資料庫
On Error GoTo EH
Set stm = New ADODB.Stream
rs.Open "select ImagePath,ImageValue from tbl_Image", cn, adOpenKeyset, adLockOptimistic
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName

With stm
.Type = adTypeBinary
.Open
.LoadFromFile CommonDialog1.FileName
End With
With rs
.AddNew
.Fields("ImagePath") = Text1.Text
.Fields("ImageValue") = stm.Read
.Update
End With
rs.Close
Set rs = Nothing
Exit Sub
EH: MsgBox Err.Description, vbInformation, "Error"
End Sub

Sub LoadPictureFromDB(cn As ADODB.Connection)
'載資料庫中讀出圖片
On Error GoTo EH
Dim strTemp As String
Set stm = New ADODB.Stream
strTemp = "c:/temp.tmp" '臨時文件,用來保存讀出的圖片
rs.Open "select ImagePath,ImageValue from tbl_image", cn, , , adCmdText
With stm
.Type = adTypeBinary
.Open
.Write rs("ImageValue")
.SaveToFile strTemp, adSaveCreateOverWrite
.Close
End With
Image1.Picture = LoadPicture(strTemp)
Set stm = Nothing
rs.Close
Set rs = Nothing
Exit Sub
EH: MsgBox Err.Description, vbInformation, "Error"
End Sub
也可用FileSystemObject的方式來保存
Dim Sql As String
Dim fs As New FileSystemObject
Sub SavePicture()
Dim sByte() As Byte
Dim bIsNull As Boolean

If fs.FileExists(g_FilePath) Then
Open g_FilePath For Binary Access Read As #1
ReDim sByte(1 To LOF(1))
Get #1, 1, sByte()
Close #1
bIsNull = False
Else
bIsNull = True
End If

Dim rs As New ADODB.Recordset
rs.Open "select empid,empname,pic from emp where empid = '" & Trim(txtEmpId.Text) & "'", cn, adOpenStatic, adLockOptimistic
rs.AddNew
rs!EmpId = txtEmpId.Text
rs!EmpName = txtEmpName.Text
If bIsNull <> True Then
rs!pic = sByte
End If
rs.Update
MsgBox "save data ok!"
txtEmpId.Text = ""
txtEmpName.Text = ""
Set picView.Picture = Nothing
cmdAdd.Enabled = True
End Sub
Sub viewJpg()

Dim TmpFile As String
Dim jByte() As Byte
Sql = "select * from emp"
Set rsViewJpg = New ADODB.Recordset
rsViewJpg.Open Sql, cn, adOpenStatic, adLockOptimistic
rsViewJpg.MoveFirst

If Not rsViewJpg.BOF Then
If Not rsViewJpg.EOF Then
txtEmpId.Text = rsViewJpg!EmpId
txtEmpName.Text = rsViewJpg!EmpName
Set pic.Picture = Nothing
If Not fs.FolderExists(App.Path + "/temp") Then
fs.CreateFolder (App.Path + "/temp")
End If
TmpFile = App.Path + "/Temp/" + rsViewJpg.Fields(0) + ".jpg"
If Not IsNull(rsViewJpg!pic) Then
jByte = rsViewJpg!pic
Open TmpFile For Binary Access Write As #1
Put #1, , jByte
Close #1
pic.Picture = LoadPicture(TmpFile)
End If
End If
End If
End Sub

熱點內容
php獲取瀏覽器 發布:2025-03-11 09:03:31 瀏覽:876
安卓常駐後台需要什麼許可權 發布:2025-03-11 08:58:26 瀏覽:180
綠源電動車威牛是什麼配置 發布:2025-03-11 08:47:34 瀏覽:9
wps加密文件密碼忘記 發布:2025-03-11 08:36:49 瀏覽:46
可編程渲染管線 發布:2025-03-11 08:35:23 瀏覽:454
一般人手機設置密碼會是什麼 發布:2025-03-11 08:27:19 瀏覽:415
緩存電視劇軟體 發布:2025-03-11 08:26:26 瀏覽:134
安卓怎麼下載ios14 發布:2025-03-11 08:25:50 瀏覽:566
軟體調試源碼 發布:2025-03-11 08:24:59 瀏覽:488
剪輯視頻怎麼配置解說 發布:2025-03-11 08:24:23 瀏覽:264