用Stream储存图片二进制数据到数据库LongBlob字段的奇怪问题
VB链接mysql,目的是读取图片二进制数据,然后储存到数据库LongBlob字段。代码如下:-----------------------------
Public Sub streamaddpic()
Dim Con As ADODB.Connection
Dim Rec As ADODB.Recordset
Dim Stm As ADODB.Stream
Set Con = New ADODB.Connection
Con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};" + _
"Server=localhost;" + _
"DB=vbadb;" + _
"UID=ABC;" + _
"PWD=abc;" + _
"OPTION=3;" + _
"Stmt=Set Names 'GBK';"
Con.Open
Set Rec = New ADODB.Recordset
Rec.CursorLocation = adUseClient
Rec.Open "select * from animal", Con, adOpenDynamic, adLockOptimistic, adCmdText
Rec.AddNew
Set Stm = New ADODB.Stream
With Stm
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.LoadFromFile "C:\pic\qq.bmp"
Rec("pic").Value = .Read
End With
Rec.Update
Stm.Close: Set Stm = Nothing
Rec.Close: Set Rec = Nothing
Con.Close: Set Con = Nothing
End Sub
-----------------------------
运行到 Rec.Update 时提示出错:
运行时错误 '-2147217887 (80040e21)':
[MySQL][ODBC 3.51 Driver][mysqld-5.5.12-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '~S;’g${O(?6Ž`!yK-…W-…W5_9‘c/‡Y(?)‚T/‰[/‰[4Ž`3_/‰[-‡Y0Š\\+…W5' at line 1
qq.bmp图片的大小是163,110 字节。
令人困惑的是,加载另外一个图片(811,694 字节)上面的代码却没有提示出错,储存到数据库成功后也能正常读取存为图片。
另外,经过测试,Rec("pic").Value = .Read 改为 Rec("pic").Value = .Read(2048),并无错误提示。(当然,这样不能正常读取存为图片。)
求教各位大侠,这代码问题出在哪里?怎么改正?
--------------------编程问答-------------------- http://download.csdn.net/detail/veron_04/1483930 --------------------编程问答-------------------- 问题解决了吗
补充:VB , 数据库(包含打印,安装,报表)