百分求教。[特来数据库论坛区求教]ADOQuery的纯SQL语句保存与读取图片的代码。

zxy_net 2004-11-21 06:38:29
代码片段
sqlStr+=":Pic,"
-------------------
TMemoryStream *MS = new(TMemoryStream);
AdvPicture1->Picture->SaveToStream(MS);
MS->Seek(0, soFromBeginning);
ADOLook->Parameters->ParseSQL(sqlStr, true);
ADOLook->Parameters->ParamByName("Pic")->LoadFromStream(MS,ftBlob);
ADOLook->Close();

ADOLook->SQL->Clear();
ADOLook->SQL->Add(sqlStr);
ADOLook->ExecSQL();

我的代码执行后,却没有把数据保存到数据库
...全文
120 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
davorsuker39 2004-11-22
  • 打赏
  • 举报
回复
你这个是SQL代码??没有看到过
了缘 2004-11-22
  • 打赏
  • 举报
回复
你应该检查你的SQL代码
AndyZhang_ 2004-11-21
  • 打赏
  • 举报
回复
[推荐]VB读取sqlserver中图片
保存图片到SQL Server
Private Sub ImportBLOB(cn As ADODB.Connection)

Dim rs As New ADODB.Recordset
Dim stm As ADODB.Stream

Set stm = New ADODB.Stream

' Skip any table not found errors
On Error Resume Next
cn.Execute "drop table BinaryObject"

On Error GoTo 0
'Create the BinaryObject table
cn.Execute "create table BinaryObject " & _
"(blob_id int IDENTITY(1,1), " & _
"blob_filename varchar(256), " & _
"blob_object image)"

rs.Open "Select * from BinaryObject where 1=2", cn, adOpenKeyset, adLockOptimistic
'Read the binary files from disk
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile App.Path & "\BLOBsample.jpg"

rs.AddNew
rs!blob_filename = App.Path & "\BLOBsample.jpg"
rs!blob_object = stm.Read

'Insert the binary object in the table
rs.Update

rs.Close
stm.Close

Set rs = Nothing
Set stm = Nothing
End Sub

显示图片
Private Sub DisplayBLOB(cn As ADODB.Connection)

Dim rs As New ADODB.Recordset

' Select the only image in the table
rs.Open "Select * from BinaryObject where blob_id = 1", cn

' Set the DataSource to the recordset
Set imgBinaryData.DataSource = rs
'Set the DataField to the BLOB field
imgBinaryData.DataField = rs!blob_object.Name

'Release the recordset
rs.Close
Set rs = Nothing
End Sub
zanyzyg 2004-11-21
  • 打赏
  • 举报
回复

ADOLook->Close();

ADOLook->SQL->Clear();

在下水平太低,不知道你这是什么语言,不过,你为什么关了后马上清空呢?

zxy_net 2004-11-21
  • 打赏
  • 举报
回复
到底why? i not明白.
:(

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧