Delphi 将JPG图片上传到SqlServer数据库里


本文整理自网络,侵删。

 Delphi 将JPG图片上传到SqlServer数据库里 


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Jpeg, StdCtrls, ADODB, DB;

type
TForm1 = class(TForm)
Button1: TButton;
ADOQuery1: TADOQuery;
procedure UploadJPGToSqlServer(UserName, path, ConnStr: String);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
//www.3464.com
implementation

{$R *.dfm}
procedure TForm1.UploadJPGToSqlServer(UserName, path, ConnStr: String);
var
tb: TADOQuery;
Begin

tb := TADOQuery.Create(self);
tb.ConnectionString := ConnStr;

// 删除数据
tb.SQL.Clear;
tb.SQL.Text := 'Delete From JPEG Where UserName='''+UserName+'''';
tb.ExecSQL;

// 插入数据
tb.SQL.Clear;
tb.SQL.Text := 'Select * from JPEG Where UserName='''+UserName+'''';
tb.Open;
if not(tb.State in [dsEdit, dsInsert]) then tb.Insert;
(tb.FieldByName('JPEG') as TBlobField).LoadFromFile(path);
tb.FieldByName('UserName').Text := UserName;
tb.Post;
tb.Close;
tb.Free;
MessageBox(handle, '上传成功' ,'系统提示' , MB_OK);

End;

procedure TForm1.Button1Click(Sender: TObject);
var
StrConn, UserName, Path: String;
begin
StrConn := 'Provider=SQLOLEDB.1;Password=#这里是密码#;Persist Security Info=True;User ID=#这里是Sql登陆名#;Initial Catalog=#这里是数据库名#;Data Source=#这里是数据库的地址#';
UserName := '龚韬';
Path := 'C:\Inetpub\wwwroot\yizhi\Images\bgtitle.jpg';
UploadJPGToSqlServer(UserName, Path, StrConn);
end;

end.



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/swei315/archive/2009/06/18/4281356.aspx

相关阅读 >>

Delphi 文件大小 显示k kb mb gb tb

Delphi从内存(memorystream)使用wmp

Delphi drawing text 绘制文本

关于Delphi xe2的fmx的一点点研究之消息篇

Delphi 读取eset nod32 的用户名与密码

Delphi 纯window系统api实现的ssl客户端

Delphi中使用临界区来让线程同步

crc16unt.pas

Delphi base32 的加密和解密

Delphi 2009 indy10 idhttp get 中文出现乱码的问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...