对不起,我没听清楚,理解能力差了点,请在说一边?!
解决方案 »
- 读文本文件和ini文件
- vb写的串口通讯软件跟手机通讯,出现8020错误,为啥啊?
- 请各位高手帮我看看这段代码?
- 救救我吧,如何在程序中控制读取扫描仪?
- vb 有什么好的辅助开发工具 在线求
- 请教在VB中如何调用ORACLE中的PACKAGE,并获取其返回值
- 如何使一个无边框的平面窗体通过拖曳窗体的四边界来改变窗体的大小,另外如何改变边框的颜色?
- 求比DevPower Button Bar好的类似控件.
- 怎么下载迪威啊
- 急急急!!!关于vb中ado实现查询
- ★听说VB对Win2000的注册表进行读写有一定的问题,请问哪位高手有圆满的解决方案,请拿出来共享。我给分!★
- 那有Active Report的正式版?有没有其他打印控件能实现类似打印名片的功能?
1.向SQL Server储存图片
创建一个测试表:
CREATE TABLE [dbo].[TABLE1] (
[Image_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Image_File] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO2.储存图片
Private Sub Form_Load()
Dim oStream As New ADODB.Stream
Dim binFile As Variant
oStream.Mode = adModeReadWrite
oStream.Type = adTypeBinary
oStream.Open
oStream.LoadFromFile "D:\sample.jpg"
binFile = oStream.Read(-1)
oStream.Close
Set oStream = Nothing
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "dsn=test;uid=sa"
rs.Open "select Image_File from table1 where 1<>1", cn, 3, 3
rs.AddNew
rs.Fields("Image_File").AppendChunk binFile
rs.Update
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub3.从读取SQL Server读取图片:
添加一个PictureBox和CommandButton
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "dsn=test;uid=sa"
rs.Open "select Image_File from table1 where Image_ID=1", cn, 3, 3
Set Me.Picture1.DataSource = rs
Me.Picture1.DataField = "Image_File"
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
测试环境:VB6.0+SQL Server7.0
回复人: yjqing(蓝歌) (2001-8-25 8:35:54) 得0分
谢谢!我先测试一下。分先送上。
回复人: suker2000(飘) (2001-8-25 9:23:03) 得0分
please refer....Public Sub ShowImage(pDb As Object, pFace As Object, pImage As Object, pChunkSize As Long, pSql As String)
On Error GoTo Errhandler
Dim lngOffset As Long
Dim lngLogoSize As Long
Dim varLogo As Variant
Dim varChunk As Variant
Dim i As Long
Dim Fragment As Integer, Chunk() As Byte
Dim Chunks As Integer
Dim FileName As String
Dim DataFile As Integer
Dim rsTmp As ADODB.Recordset
Set rsTmp = New ADODB.Recordset
Set rsTmp = pDb.DoSQLQuery(pSql)
If Not rsTmp.EOF Then
lngLogoSize = rsTmp.Fields("photo").ActualSize '相片大小
If lngLogoSize = 0 Then
pImage.Picture = LoadPicture("")
Exit Sub
End If
DataFile = 1
FileName = App.Path & "\temp.bmp"
gPhotoPath = FileName
Open FileName For Binary Access Write As DataFile
Chunks = lngLogoSize \ pChunkSize
Fragment = lngLogoSize Mod pChunkSize
ReDim Chunk(Fragment)
Chunk() = rsTmp!photo.GetChunk(Fragment)
Put DataFile, , Chunk()
' For i = 1 To Chunks
' ReDim Buffer(pChunkSize)
' Chunk() = rsTmp!photo.GetChunk(pChunkSize)
' Put DataFile, , Chunk()
' Next i
Close DataFile
pImage.Picture = LoadPicture(FileName)
Else
pImage.Picture = LoadPicture("")
End If
Set rsTmp = Nothing
Exit Sub
Errhandler:
Set rsTmp = Nothing
HandleError pFace
End Sub
Public Sub SaveImage(pServer As String, pSessionId As String, pFace As Object, pImage As Object, pSql As String, pChunkSize As Long, Optional pFlag As String = "", Optional pPath As String = "", Optional pValue As String = "")
On Error GoTo Errhandler
Dim TmpPhoto As Object 'hrms.clsPhoto
Dim lngLogoSize As Long
Dim Fragment As Integer, Chunk() As Byte
Dim Chunks As Integer
Dim msg As String
Dim i As Long
Dim isok As Boolean Dim FileName As String
Dim DataFile As Integer
FileName = pPath DataFile = 1
Open FileName For Binary Access Read As DataFile
lngLogoSize = LOF(DataFile)
If lngLogoSize = 0 Then Close DataFile: Exit Sub
Chunks = lngLogoSize \ pChunkSize
Fragment = lngLogoSize Mod pChunkSize
If Chunks > 0 Then
' MsgBox pFace.res.GetString(1070)
pFace.MsgInfoById (1070)
Close DataFile
Exit Sub
End If
' rsTmp!photo.AppendChunk Null
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
' rsTmp!photo.AppendChunk Chunk()
' ReDim Chunk(pChunkSize)
' For i = 1 To Chunks
' Get DataFile, , Chunk()
' rsTmp!photo.AppendChunk Chunk()
' Next i Set TmpPhoto = CreateObject("hrms.clsPhoto")
TmpPhoto.ConnectDB pServer, pSessionId, GetMacAddress
TmpPhoto.UpdateImage pSql, Chunk, pFlag, pValue
' If pFlag = "0" Then
' pImage.Picture = LoadPicture("")
' End If
Close DataFile Set TmpPhoto = Nothing
Exit Sub
Errhandler:
Set TmpPhoto = Nothing
HandleError pFace
End Sub
其实你也可以用"图片"查查以前的论坛,有很多讲到的