如何读取SQL中某个表的image字段?我的代码好象写入可以,但读出就不行,为何
这个问题我也一直在关注这类问题,如何查看这个字段是否正确读进到SQL中去了...我的代码如下: image 字段
Private Sub Command2_Click()
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim strCn As String, strSQL As String
strCn = "Provider=sqloledb;server=.;Database=456;Uid=sa;Pwd=;"
cn.Open strCn
rs.Open "select * from yuangong ", cn, 3, 3
MsgBox "OK,打开了记录集"
Dim mst As ADODB.Stream
Set mst = New ADODB.Stream
mst.Type = adTypeBinary
mst.Open
mst.LoadFromFile ("F:\狗5.jpg")
rs.AddNew
rs.Fields("ygname") = Text1.Text
rs.Fields("ygxb") = Text2.Text
rs.Fields("ygchusheng") = Text3.Text
rs.Fields("ygpicuter").Value = mst.Read '写入数据库是OK的,好象正确的,添加后能发现新记录中ygpicuter字段,写成了<二进制数据>,这样是否说明正确的写进了SQL数据库中呢???
rs.Update
MsgBox "OK,图片和记录已经插入到数据库中去了!赶快去查看一下吧"
rs.Close
Set rs = Nothing
Set rs = New ADODB.Recordset
end sub
Private Sub 读取图片格式()
'On Error GoTo EH
Dim strTemp As String
Set stm = New ADODB.Stream
Set rs = New ADODB.Recordset
strTemp = "c:\temp.tmp " '临时文件,用来保存读出的图片
rs.Open "select * from yuangong where ygname='张**'", cn, 1, 1, adCmdText'" & Text1.Text & "
'这行就报错.参数类型不正确,或不在可以接受的范围之内,或与其他对数冲突...'
With stm
.Type = adTypeBinary
.Open
.Write rs("ygpicuter ")
.SaveToFile strTemp, adSaveCreateOverWrite
.Close
End With
Picture1.Picture = LoadPicture(strTemp) Set stm = Nothing
rs.Close
Set rs = Nothing
Exit Sub
EH: MsgBox Err.Description, vbInformation, "Error "
End Sub
但报错..说参数类型不正确,或不在可以接受的范围之内,或与其他对数冲突.
格式不对?何解,我要首先确定是否写入了SQL,然后再说才正确读出来,,,,请高手出手说明一下..谢谢!