注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
从Melissa到Zotob:Windows蠕虫1
从后台得到webshell技巧大汇总
Qmail邮件系统下防止滥用mail re
Qmail邮件系统下防止滥用mail re
使用telnet 方式连接Imail的SMTP
MDeamon Server 邮件系统迁移完全
用RelayFax搭建传真服务器
Qmail邮件系统下防止滥用mail re
隐藏qmail的SMTP help信息保护你
Sendmail的relay用法汇总
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> Delphi >> 文章正文
在DELPHI中更简单的存取JPEG文件到SQLSERVER数据库
作者:loveghb  来源:csdn  点击:  更新:2006-12-19
简介:
 

最近在CSDN上看到两篇关于《DELPHI中存取JPEG文件到SQLSERVER》中的文章之后,觉得其中讲述的方法虽然有可取之处,但颇费时,我这里有更简单的操作方法,而且安全可靠,不敢一人独享,愿发布出来与大家共享。在Delphi7.0+Win2000+SqlServer 2000中测试通过,运行良好,现将思路、源码公开如下:

解决思路:

1、 关键在于将打开的JPEG文件动态转换为Tbitmap对象并显示在Timage对象中;

2、 将显示的图片提交到数据库中。

本例中在SQLSERVER2000中建立了一个试例表:exam(xm char(10),photo image);

 

程序源代码:

unit SavePic;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtDlgs, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB, Buttons,

  StdCtrls,Jpeg;

 

type

  TForm1 = class(TForm)

    SpeedButton1: TSpeedButton;

    ADOConnection1: TADOConnection;

    Table1: TADOTable;

    DataSource1: TDataSource;

    DBGrid1: TDBGrid;

    DBImage1: TDBImage;

    Image1: TImage;

    SpeedButton2: TSpeedButton;

    OpenPictureDialog1: TOpenPictureDialog;

    Label1: TLabel;

    Label2: TLabel;

    Edit1: TEdit;

    SpeedButton3: TSpeedButton;

    procedure SpeedButton2Click(Sender: TObject);

    procedure SpeedButton1Click(Sender: TObject);

    procedure SpeedButton3Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

procedure TForm1.SpeedButton2Click(Sender: TObject);

var

  bmp1:TBitmap;

  jpg1:TJpegImage;

begin

 

  OpenPictureDialog1.DefaultExt:=GraphicExtension(TJpegimage);

  if OpenPictureDialog1.Execute then

     begin

     bmp1:=TBitmap.Create;

     jpg1:=TJpegImage.Create;

     try

     jpg1.LoadFromFile(OpenPictureDialog1.FileName);

     bmp1.Assign(jpg1);

     Image1.Picture.Bitmap.Assign(bmp1);

     finally

       jpg1.Free;

       bmp1.Free;

     end;

    end;

end;

 

procedure TForm1.SpeedButton1Click(Sender: TObject);

begin

  table1.Open;

  table1.insert;

  table1.fieldbyname('xm').asstring:=Edit1.Text;

  table1.FieldByName('photo').Assign(Image1.Picture);

  table1.post;

  table1.Refresh;

end;

end.






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务