加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

BCB保存图片到SQLSERVER

发布时间:2020-12-12 12:42:35 所属栏目:MsSql教程 来源:网络整理
导读:void __fastcall TForm1::btn6Click(TObject *Sender) ? //存储图片 { ? ? ? TMemoryStream * MemoryImageStream=new TMemoryStream; ? ? ? ? ? ? ? ? ? ? ? ?//A ? ? ? img1-Picture-Graphic-SaveToStream(MemoryImageStream); ? ? ? ? ? ? ? ? ? ?//B ? ?
void __fastcall TForm1::btn6Click(TObject *Sender) ? //存储图片 { ? ? ? TMemoryStream * MemoryImageStream=new TMemoryStream; ? ? ? ? ? ? ? ? ? ? ? ?//A ? ? ? img1->Picture->Graphic->SaveToStream(MemoryImageStream); ? ? ? ? ? ? ? ? ? ?//B ? ? ? AnsiString strSql = "insert into tab_img(Img) values(:Img)"; ? ? ? qry1->Close(); ? ? ? qry1->SQL->Clear(); ? ? ? qry1->SQL->Add(strSql); ? ? ? TJPEGImage *pJPG = new TJPEGImage; ? ? ? pJPG->Assign(img1->Picture->Graphic); ? ? ? pJPG->SaveToStream(MemoryImageStream); ? ? ? MemoryImageStream->Position = 0; ? ? ? this->qry1->Parameters->ParamByName("Img")->LoadFromStream(MemoryImageStream,ftBlob); ? ? ? qry1->ExecSQL(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //E ? ? ? ?delete MemoryImageStream; ? ? ? ?delete pJPG; } //--------------------------------------------------------------------------- void __fastcall TForm1::btn7Click(TObject *Sender) ?//加载图片 { ? ? ? TMemoryStream * MemoryImageStream=new TMemoryStream; ? ? ? ? ? ? ? ? ? ? ? ?//A ? ? ? img1->Picture->Graphic->SaveToStream(MemoryImageStream); ? ? ? ? ? ? ? ? ? ?//B ? ? ? AnsiString strSql = "select top 1 * from tab_img"; ? ? ? qry1->Close(); ? ? ? qry1->SQL->Clear(); ? ? ? qry1->SQL->Add(strSql); ? ? ? qry1->Open(); ? ? ? if(!qry1->Eof) ? ? ? { ? ? ? ? if(qry1->FieldByName("Img")) ? ? ? ? { ? ? ? ? ? ? ((TBlobField*)(qry1->FieldByName("Img")))->SaveToStream(MemoryImageStream); ? ? ? ? ? ? TJPEGImage *pJPG = new TJPEGImage; ? ? ? ? ? ? MemoryImageStream->Position = 0; ? ? ? ? ? ? pJPG->LoadFromStream(MemoryImageStream); ? ? ? ? ? ? img2->Picture->Assign(pJPG); ? ? ? ? ? ? if(MemoryImageStream != NULL) ? ? ? ? ? ? { ? ? ? ? ? ? ? ?delete MemoryImageStream; ? ? ? ? ? ? ? ?MemoryImageStream = NULL; ? ? ? ? ? ? } ? ? ? ? ? ? if(pJPG != NULL) ? ? ? ? ? ? { ? ? ? ? ? ? ? ?delete pJPG; ? ? ? ? ? ? ? pJPG = NULL; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? else ? ? ? ? img2->Picture = NULL; ? ? ? } } //---------------------------------------------------------------------------

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读