当前位置:首页 » 操作系统 » 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

热点内容
安卓机怎么领岭南通 发布:2025-03-11 05:56:54 浏览:130
求生之路2虐电脑服务器 发布:2025-03-11 05:35:40 浏览:631
编译学堂 发布:2025-03-11 05:31:06 浏览:184
苹果文件夹隐藏 发布:2025-03-11 05:26:42 浏览:544
短信设置密码如何关闭 发布:2025-03-11 05:26:39 浏览:913
re管理器主文件夹 发布:2025-03-11 05:26:37 浏览:712
手机优酷缓存在哪 发布:2025-03-11 05:25:58 浏览:432
摩擦引流脚本 发布:2025-03-11 05:17:31 浏览:544
中国电信的路由器密码在哪里更改 发布:2025-03-11 05:10:40 浏览:686
我的世界电脑服务器必用指令 发布:2025-03-11 05:10:31 浏览:632