Save image in SQL Server (delphi)

{

if object_id('test', 'U') is not null
    drop table test
go
create table test(cid int identity, ctext text, cimage image)
insert test(ctext, cimage) select '', 0x0

}

{

C:/>textcopy /S. /Usa /P /DMyDB /Ttest /Cctext /W"where cid = 1" /Fa.txt /I /Z
TEXTCOPY Version 1.0
DB-Library version 8.00.194
  debug: Final parameters:
  debug:   Server: .
  debug:   Login: sa
  debug:   Password:
  debug:   Database: MyDB
  debug:   Table: test
  debug:   Column: ctext
  debug:   Where clause: where cid = 1
  debug:   File: a.txt
  debug:   Direction: Into SQL Server from file.
  debug:   Chunk size: 4096 bytes
SQL Server 'DSHB-1' Message 5701: Changed database context to 'MyDB'.
SQL Server 'DSHB-1' Message 5701: Changed database context to 'MyDB'. (Concerning line 1)
  debug: Query: select ctext from test where cid = 1
  debug: File 'a.txt' opened for read
  debug: File is 639 bytes long
  debug: Read 639 bytes from file
  debug: File closed
Data copied into SQL Server text column from file 'a.txt'.


C:/>textcopy /I /Usa /Ppwd /S. /DMyDB /Ttest /Ccimage /W"where cid = 1" /Fa.bmp /Z
TEXTCOPY Version 1.0
DB-Library version 8.00.194
  debug: Final parameters:
  debug:   Server: .
  debug:   Login: sa
  debug:   Password:
  debug:   Database: MyDB
  debug:   Table: test
  debug:   Column: cimage
  debug:   Where clause: where cid = 1
  debug:   File: a.bmp
  debug:   Direction: Into SQL Server from file.
  debug:   Chunk size: 4096 bytes
SQL Server 'DSHB-1' Message 5701: Changed database context to 'MyDB'.
SQL Server 'DSHB-1' Message 5701: Changed database context to 'MyDB'. (Concerning line 1)
  debug: Query: select cimage from test where cid = 1
  debug: File 'a.bmp' opened for read
  debug: File is 3510 bytes long
  debug: Read 3510 bytes from file
  debug: File closed
Data copied into SQL Server image column from file 'a.bmp'.
}


{
By the way, you should insert something into text/image column before copy text/image into it. I mean, this value should not be null. You should write (for example):

INSERT INTO [dbo].[images] VALUES ('1', 0x0, null)

instead of:

INSERT INTO [dbo].[images] VALUES ('1', null, null)

Otherwise, you will get the following error message:

ERROR: Text or image pointer and timestamp retrieval failed.

}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls, DBCtrls;

type
  TForm1 = class(TForm)
    ADOTable1: TADOTable;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    DBMemo1: TDBMemo;
    DBImage1: TDBImage;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值