1) 保存 图片文件 路径2)
二进制 存储图片.下面的帖子中,有我的回答:MSDN 例子
http://www.csdn.net/expert/topic/622/622655.xml?temp=.5135767谁能提供一个将图片写入Access数据库的例子(不是写入图片保存路径,而是写入库中)?
http://www.csdn.net/Expert/topic/407/407218.xml如何在SQLSERVER2000中存取图片?
http://www.csdn.net/Expert/topic/433/433195.xml
二进制 存储图片.下面的帖子中,有我的回答:MSDN 例子
http://www.csdn.net/expert/topic/622/622655.xml?temp=.5135767谁能提供一个将图片写入Access数据库的例子(不是写入图片保存路径,而是写入库中)?
http://www.csdn.net/Expert/topic/407/407218.xml如何在SQLSERVER2000中存取图片?
http://www.csdn.net/Expert/topic/433/433195.xml
《 在VB中存取数据库中的图片 》
一、 数据库的设计 数据库可以采用微软的Access97或者SQL Server来进行,首先新建一张表,取名为Table,添加三个字段,分别是:姓名 Char型(SQL Server中)文本型(Access中);编号Char型(SQL Server中)文本型(Access中);照片image型(SQL Server中)OLE对象(Access中),设计好后存盘。为了可以进行远程调用,我们采用ODBC的方法进行,双击打开控制面板里的ODBC数据源,界面如图1所示:
点“系统DSN”选项卡,按“添加”按钮选择对应的数据源驱动程序Access的*.mdb或者SQL Server,依照添加向导加添加数据源,下面就可以开始程序的编写了。
二、 程序的编写 运行VB,新建一个工程。本程序采用ADO控件和动态链接库访问数据库,需要加入ADO的运行库,单击“工程\引用”菜单,出现引用对话框,选择Microsoft ActiveX Data Objects2.0 Library并确定。
添加一个Form,四个Label控件,两个TextBox控件,一个PictureBox控件,一个ADODC控件,三个CommandButton控件,一个CommandDialog控件,如果ADODC和CommandDialog控件没有出现在工具框上,请单击菜单“工程\部件”。点“控件”选项卡,在其中选中Microsoft ADO Data Control 6.0(OLEDB)和Microsoft Common Dialog Control 6.0两项按“确定”按钮。
下面是以上各个控件的一些属性:
Form1.MaxButton=False
Label1.Caption=姓名:
Label2.Caption=编号:
Label3.Name= ResName
Label3.BackColor= &H80000009&
Label3.BorderStyle=1-Fixed Single
Label3.DataField=姓名
Label3.DataSource= AdoCtr
Label4.Name= ResNumb
Label4.BackColor= &H80000009&
Label4.BorderStyle=1-Fixed Single
Label4.DataField=编号
Label4.DataSource= AdoCtr
Text1.Name= Names
Text2.Name= Numb
CommonDialog1.Name= CDlg
Adodc1.Name=AdoCtr
CommonButton1.Name=PreView
CommonButton1.Caption=预览
CommonButton2.Name=Save
CommonButton2.Caption=保存
CommonButton3.Name= Update
CommonButton3.Caption=更新
PictureBox1.Name= PicBox
PictureBox1.AutoSize=False
PictureBox1.AutoRedraw=False
PictureBox1.DataField=照片
PictureBox1.DataSource=AdpCtr
下面是程序代码:
′此工程需有Microsoft ActiveX Data Object 2.1 Library(msado15.dll)
Dim Constr As String ′ODBC路径
Dim FileName As String ′图片文件名
Const BLOCKSIZE = 4096 ′每次读写块的大小
PictureBox直接绑定就可以了
PicData.Recordset.AddNew
txtRoadname = CStr(Int(Rnd * 1000 + 1)) & "路"
comboDirection.ListIndex = Int(Rnd * 4)
PicData.Recordset.Fields("路口名称") = txtRoadname
PicData.Recordset.Fields("路口方向") = comboDirection
PicData.Recordset.Fields("时间") = Now
Image1.Picture = LoadPicture(App.Path + "\tmp\tmp.jpg")
PicData.Recordset.Update
显示更简单了,只要
picData.Recordset.FindFirst "系统编号=" & Index
就可以了假如用ADO,还请参考以上方法
该范例使用 AppendChunk 和 GetChunk 方法用其他记录中的数据填写图像字段。Public Sub AppendChunkX() Dim cnn1 As ADODB.Connection
Dim rstPubInfo As ADODB.Recordset
Dim strCnn As String
Dim strPubID As String
Dim strPRInfo As String
Dim lngOffset As Long
Dim lngLogoSize As Long
Dim varLogo As Variant
Dim varChunk As Variant
Const conChunkSize = 100 ' 打开连接
Set cnn1 = New ADODB.Connection
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
cnn1.Open strCnn
' 打开 pub_info 表。
Set rstPubInfo = New ADODB.Recordset
rstPubInfo.CursorType = adOpenKeyset
rstPubInfo.LockType = adLockOptimistic
rstPubInfo.Open "pub_info", cnn1, , , adCmdTable
' 提示复制徽标。
strMsg = "Available logos are : " & vbCr & vbCr
Do While Not rstPubInfo.EOF
strMsg = strMsg & rstPubInfo!pub_id & vbCr & _
Left(rstPubInfo!pr_info, InStr(rstPubInfo!pr_info, ",") - 1) & _
vbCr & vbCr
rstPubInfo.MoveNext
Loop
strMsg = strMsg & "Enter the ID of a logo to copy:"
strPubID = InputBox(strMsg)
' 将徽标复制到大块中的变量。
rstPubInfo.Filter = "pub_id = '" & strPubID & "'"
lngLogoSize = rstPubInfo!logo.ActualSize
Do While lngOffset < lngLogoSize
varChunk = rstPubInfo!logo.GetChunk(conChunkSize)
varLogo = varLogo & varChunk
lngOffset = lngOffset + conChunkSize
Loop
' 从用户得到数据。
strPubID = Trim(InputBox("Enter a new pub ID:"))
strPRInfo = Trim(InputBox("Enter descriptive text:"))
' 添加新记录,将徽标复制到大块中。
rstPubInfo.AddNew
rstPubInfo!pub_id = strPubID
rstPubInfo!pr_info = strPRInfo lngOffset = 0 ' 重置位移。
Do While lngOffset < lngLogoSize
varChunk = LeftB(RightB(varLogo, lngLogoSize - lngOffset), _
conChunkSize)
rstPubInfo!logo.AppendChunk varChunk
lngOffset = lngOffset + conChunkSize
Loop
rstPubInfo.Update
' 显示新添加的数据。
MsgBox "New record: " & rstPubInfo!pub_id & vbCr & _
"Description: " & rstPubInfo!pr_info & vbCr & _
"Logo size: " & rstPubInfo!logo.ActualSize ' 删除新记录,因为这只是演示。
rstPubInfo.Requery
cnn1.Execute "DELETE FROM pub_info " & _
"WHERE pub_id = '" & strPubID & "'" rstPubInfo.Close
cnn1.Close End Sub
`连接数据库
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
Dim STRconn As String
STRconn = "PROVIDER=MSDASQL;driver={SQL Server};server=" & sn & ";uid=" & uid & ";pwd=" & pw & ";database=" & dbn & ";"
db.Open STRconn
Dim adoRSet As Recordset
Set adoRSet = New ADODB.Recordset
adoRSet.Open "ArchivesEquipment", db, adOpenKeyset, adLockOptimistic, adCmdTable'将图片复制到大块变量
Dim DataFile As Integer, Chunks As Integer
Dim Fragment As Integer, chunk() As Byte, i As Integer
Const ChunkSize As Integer = 16384
DataFile = 1
Open StrFN For Binary Access Read Write As DataFile
lngLogoSize = LOF(DataFile)
If lngLogoSize = 0 Then Close DataFile: Exit Sub
Chunks = lngLogoSize \ ChunkSize
Fragment = lngLogoSize Mod ChunkSize - 1
adoRSet!图片.AppendChunk Null
ReDim chunk(Fragment)
Get DataFile, , chunk()
adoRSet!图片.AppendChunk chunk()
ReDim chunk(ChunkSize - 1)
For i = 1 To Chunks
Get DataFile, , chunk()
adoRSet!图片.AppendChunk chunk()
Next i
Close DataFile
adoRSet.Update
http://www.applevb.com/sourcecode/sqlserver%20image.zip