首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

请教,VB中怎么向MYSQL数据库中插入图片呀.(BLOB数据类型),最好有代码,请高手看过来

2012-01-08 
请问,VB中如何向MYSQL数据库中插入图片呀..(BLOB数据类型),最好有代码,请高手看过来请问,VB中如何向MYSQL

请问,VB中如何向MYSQL数据库中插入图片呀..(BLOB数据类型),最好有代码,请高手看过来
请问,VB中如何向MYSQL数据库中插入图片呀..(BLOB数据类型),最好有代码,请高手看过来

[解决办法]
..........................
[解决办法]
个人想法:
不用在数据库中存放图片,而采用存放图片路径的方式如何?
[解决办法]
请参考
Public Sub SaveImage(pImage As Object, pSql As String, pChunkSize As Long,Optional pPath As String = " ", Optional pValue As String = " ")
On Error GoTo Errhandler
Dim TmpPhoto As Object
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
End Sub
[解决办法]
very good
[解决办法]
http://topic.csdn.net/t/20050331/14/3897738.html
[解决办法]
路径是UNC Path.先判断一下。再处理。
UNC path like "\\targetcomputer\sharefolder "

Public Declare Function PathIsNetworkPath Lib "SHLWAPI.DLL " Alias "PathIsNetworkPathA " (ByVal pszPath As String) As Boolean
Public Declare Function PathIsUNCServerShare Lib "SHLWAPI.DLL " Alias "PathIsUNCServerShareA " (ByVal pszPath As String) As Boolean
Public Declare Function PathIsUNC Lib "SHLWAPI.DLL " Alias "PathIsUNCA " (ByVal pszPath


Public Declare Function PathIsUNCServer Lib "SHLWAPI.DLL " Alias "PathIsUNCServerA " (ByVal pszPath As String) As Boolean

[解决办法]
我以前回答过多次此类问题,但2006年的贴子不能查到了。

VB把文件存入数据库IMAGE字段

Sub Savepic(FileName As String, IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER "
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo ", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call FileToBlob(rs.Fields( "Image "), FileName, FileLen(FileName))
rs.UpdateBatch adAffectCurrent
End Sub

Private Sub FileToBlob(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn 't support the GetChunk method. "
End If
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = LOF(fnum)
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get #1, , tmp
fld.AppendChunk tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub

VB把文件从IMAGE字段中读到文件中。

Sub loadpic(IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER "
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo ", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call BlobToFile(rs.Fields( "Image "), "c:\windows\temp\tmp.bmp ", rs.Fields( "Image ").ActualSize)
End Sub

Private Sub BlobToFile(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn 't support the GetChunk method. "
End If
If Dir$(FileName) <> " " Then Kill FileName
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = fld.ActualSize
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
tmp = fld.GetChunk(bytes)
Put #fnum, , tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub

[解决办法]
你自己修改一下.
[解决办法]
strSQL = "select * from table where aa= ' " & 11 & " ' and bb= " & 22
???

热点排行