我老婆初学VB,我又是VC中的强鸟,VB中的菜鸟,所以还请各路高手帮帮忙:)
问题是:怎么把图片放到数据库,当然也要能取得回来
我只知道用BLOB,可是我对Image控件什么的一点都不熟,所以还是靠大家了,可以的话顺便解释一下Image(或者叫Picture,我忘了)控件的绑定到数据库是怎么一回事, 多谢了
问题是:怎么把图片放到数据库,当然也要能取得回来
我只知道用BLOB,可是我对Image控件什么的一点都不熟,所以还是靠大家了,可以的话顺便解释一下Image(或者叫Picture,我忘了)控件的绑定到数据库是怎么一回事, 多谢了
解决方案 »
- VB字符串问题(在线等)
- 报表打印问题!帮忙看一下,在线等,马上结贴!
- 关于MSHFLEXGRID的问题??
- 我想实现鼠标指针移动到窗口某个区域或某个控件上面时,鼠标指针图像自动改变,应该怎么做?
- 特急~~怎么把邮件源码文件解码。~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 请问如何让在14‘显示器好的的vb界面在17’的显示器上屏显示?
- 征求SQL数据库的原代码!!谢谢!!
- 大家好!我正打算学VB,哪位能给推荐本合适的书?
- 我怎样改变sstab每一页的颜色
- 菜鸟问题(100分):为什么我开发的机子上运行程序字体是正确的,而在没有VB的机子上运行程序字体好象变小一号了
- 急:如何通过vb6将sql中的数据以及mshflexgrid中的数据导入access?
- 如何在这种情况下对数据库进行更新?
http://www.yesky.com/20010705/188008.shtmlAppendChunk and GetChunk Methods Example (VB)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdaexamples_vb01_8.aspSave/Retrieve Image From SQL Server Database Using Ado 2.5 Stream Object
http://www.freevbcode.com/ShowCode.Asp?ID=1802
我的信箱是[email protected]
Dim bit1() As Byte
xx = "select 照片 from 照片库 where 序号=" & Val(Trim(txt(1).Text))
Set rst = chaxun(xx, yy)
If rst.RecordCount > 0 Then
Image1.Picture = Nothing
If rst("照片").ActualSize > 0 Then
Image1.Stretch = False
bit1 = rst.Fields("照片").GetChunk(rst("照片").ActualSize)
'然后将字节数组的内容拼装成文件即可
Open "c:\1.bmp" For Binary As #1
Put 1, 1, bit1
Close 1
Image1.Picture = LoadPicture("c:\1.bmp")
Kill ("c:\1.bmp")
end if
Else
MsgBox "照片库无" & Trim(txt(2).Text) & "的照片", , "提示"
Check1.Value = 0
End If2、加照片Dim rst As ADODB.Recordset
xx = "select 序号 from 照片库 where 序号=" & Val(Trim(txt(1).Text))
Set rst = chaxun(xx, yy)
If rst.RecordCount > 0 Then Check1.Value = 1: Exit Sub
Dim bit() As Byte
Dim varPath As String '图片的路径
CommonDialog1.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"
CommonDialog1.ShowOpen
varPath = CommonDialog1.FileName
If varPath = "" Then Exit Sub
xx = "select * from 照片库"
Set rst = chaxun(xx, yy)
Open varPath For Binary As #1
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1
' 然后将字节数组的内容写入数据库即可
rst.AddNew
rst.Fields("照片").AppendChunk bit
rst.Fields("序号") = Val(txt(1).Text)
rst.Update
Image1.Picture = LoadPicture(varPath)
3、换照片Dim rst As ADODB.Recordset
Dim bit() As Byte
Dim varPath As String '图片的路径
CommonDialog1.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"
CommonDialog1.ShowOpen
varPath = CommonDialog1.FileName
If varPath = "" Then Exit Sub
xx = "select * from 照片库 where 序号=" & Val(Trim(txt(1).Text))
Set rst = chaxun(xx, yy)
Open varPath For Binary As #1
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1
rst.Fields("照片").AppendChunk bit
rst.Update
Image1.Picture = LoadPicture(varPath)
Image1.Refresh4、删除照片 Dim rst As ADODB.Recordset
xx = "delete from 照片库 where 序号=" & Val(Trim(txt(1).Text))
Set rst = chaxun(xx, yy)
MsgBox yy
Image1.Picture = Nothing
5、公用函数Public Function chaxun(ByVal sql As String, msgstring As String) As ADODB.Recordset
On Error GoTo ExecuteSQL_Error
Dim cN As ADODB.Connection
Dim rst As ADODB.Recordset
Dim a() As String
Set cN = New ADODB.Connection
Dim str As String
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If cN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\_data.mdb;Persist Security Info=False;jet OLEDB:Database password=422127197509080072"
cN.Open
a = Split(sql)
If InStr("insert,delete,updata", Trim(a(0))) Then
cN.Execute sql
Select Case Trim(a(0))
Case "insert"
msgstring = "添加记录"
Case "delete"
msgstring = "删除记录"
Case "updata"
msgstring = "更新记录"
End Select
msgstring = msgstring & "已完成"
Else
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open sql, cN, adOpenKeyset, adLockOptimistic
Set chaxun = rst
msgstring = "查询到" & rst.RecordCount & "条记录"
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cN = Nothing
Exit Function
ExecuteSQL_Error:
msgstring = "查询错误: " & _
err.Description
Resume ExecuteSQL_Exit
End Function
《按“添加”按钮选择对应的数据源驱动程序Access的*.mdb或者SQL Server,依照添加向导 加添加数据源》
看不懂
邮箱:[email protected]