BCB 6 SP4 + SQL Server 2k Access JPEG image, absolutely easy to use!

Source: Internet
Author: User
Tags add format sql access
Server
In the BCB 6 SP4 debugging pass, welcome prawns criticize correct.

OPENDIALOG1 Open JPEG image, Edit1 save image Address, Image1 display image//Other format image file is not tested, you can try.

Opendialog1->filename= "";          if (Opendialog1->execute ()) {edit1->text= opendialog1->filename;       Image1->picture->loadfromfile (Edit1->text); }

Below: Save the image to the SQL Server database

if (!    Edit1->text.isempty ()) {adoquery1->close ();          Add Adoconnention on your own and configure Adoquery1->sql->clear ();          Adoquery1->sql->add ("SELECT * from IMGs");          Adoquery1->open (); Adoquery1->insert ();

Adoquery1->fieldbyname ("imgaddress")->asstring=edit1->text;         Adoquery1->fieldbyname ("Imgid")->asinteger=edit2->text.toint (); The number of the saved image Tblobfield *field=dynamic_cast<tblobfield *> (Adoquery1->fieldbyname ("img"));  IMG is an image type of data field->loadfromfile (Edit1->text); Here is the key, to be directly transferred from the file. Do not tune Image1, so it is easy to "JEPG error #41" error

Adoquery1->post ();       Adoquery1->close (); }

Reading images from a database

Adoquery1->close (); Adoquery1->sql->clear (); Adoquery1->sql->add ("SELECT * from IMGs"); Ansistring ddd= "where imgid=" +edit1->text; Adoquery1->sql->add (DDD);  Adoquery1->open (); if (adoquery1->recordcount==1) {Tstream *stream1;   Tjpegimage *pjp=new tjpegimage ();    try {stream1=adoquery1->createblobstream (adoquery1->fieldbyname ("img"), bmread);    Pjp->loadfromstream (STREAM1);    Image2->picture->assign (PJP);  Delete Stream1;  } __finally {Delete pjp; }  }

PS: The first time to send an article, do not know how the format. ^_^


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.