把图片存放在数据库中
在bcb中用到的控件有ADOQuery,Button1,Button2,Edit1,image1.在数据中已经建好了表Picture(id int,pic,image,);程序里是把D盘中的一张图片存入Picture中,可是那位高手用的是XP+BCB6+Oracle9i,可是我的是XP+BCB6+SQLServer。代码是高手给的,所以希望用SQLServer的高手,修改一下。
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include"jpeg.hpp"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery1->SQL->Text="Insert into Picture values(:id,:pic)";
ADOQuery1->Parameters->Items[0]->Value=1;
ADOQuery1->Parameters->Items[1]->LoadFromFile("d:\\ FF70.JPG",ftBlob );
ADOQuery1->ExecSQL();
}
//---------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TMemoryStream *MS;
TJPEGImage *jpg;
MS = new TMemoryStream;
jpg = new TJPEGImage;
ADOQuery1->Close();
ADOQuery1->SQL->Text="select id,pic from Picture where id=1";
ADOQuery1->Open();
Edit1->Text=ADOQuery1->FieldValues["id"];
((TBlobField *)ADOQuery1->FieldByName("pic"))->SaveToStream(MS);
MS->Position=0;
jpg->LoadFromStream(MS);
Image1->Picture->Assign(jpg);
delete jpg;
delete MS;
}
//[code=C/C++][/code]
[解决办法]
程序基本没问题
ADOQuery1->Parameters->Items[1]->LoadFromFile("d:\\ FF70.JPG",ftBlob );
"d:\\ FF70.JPG"多了个空格
我用x2k+bcb6+sqlserver测试通过
[解决办法]
Oracle和SQLServer对于ADO的操作其实差不多,只是ADOConnection的连接不一样!!
[解决办法]