写入sql图片看下面的代码,注:工程引用ado2.5及以上版本才行,否则没有Stream
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As New ADODB.Stream
Private Sub Command1_Click() '读取图片
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=.;Initial Catalog=pubs;User Id=sa;Password="
Set rs = New ADODB.Recordset
rs.Open "Select * from pub_info", cn, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("logo").Value
mstream.SaveToFile "c:\publogo.gif", adSaveCreateOverWrite
rs.Close
cn.Close
End Sub
Private Sub Command2_Click() '写入图片
Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=.;Initial Catalog=pubs;User Id=sa;Password="
Set rs = New ADODB.Recordset
rs.Open "Select * from pub_info", cn, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "c:\publogo.gif"
rs.Fields("logo").Value = mstream.Read
rs.Update
rs.Close
cn.Close
End Sub