调用存储过程进行图片的插入或修改
来源:互联网 发布:美工钢笔推荐 编辑:程序博客网 时间:2024/04/30 15:09
//pass blob to stored procedure //build by masterz 20050301 with VC2003, Windows 2003, SQLServer 2000. #include "stdafx.h" #import "C:/PROGRA~1/COMMON~1/System/ado/msado15.dll" rename( "EOF", "adoEOF" ) struct InitOle { InitOle() { ::CoInitialize(NULL); } ~InitOle() { ::CoUninitialize(); } } _init_InitOle_; void PrintProviderError(ADODB::_ConnectionPtr pConnection); void print_properties(LPCTSTR name, ADODB::PropertiesPtr Properties) { long prop_count = Properties->GetCount(); printf("%s property count = %d/n",name,prop_count); for(long i=0;i<prop_count;i++) { printf("%s property [%d]:%s/n",name,i,(LPCSTR)Properties->GetItem(i)->Name); } } int main(int argc, char* argv[]) { ADODB::_ConnectionPtr Conn1; ADODB::_CommandPtr Cmd1; ADODB::_ParameterPtr oldParam= NULL; ADODB::_ParameterPtr inParam=NULL; ADODB::_ParameterPtr blobParam=NULL; _variant_t vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR); _variant_t vtEmpty2 (DISP_E_PARAMNOTFOUND, VT_ERROR); //_bstr_t bstrConnect="Provider=OraOLEDB.Oracle;Data Source=orcl;User Id=system;Password=oracle;"; _bstr_t bstrConnect="Driver={SQL Server};Server=localhost;Database=zxg;Uid=sa;Pwd=sa;" ; //create procedure dbo.insert_update_blob(@fn varchar(9),@filecontent image) as // if exists (select * from table1 where filename=@fn ) // begin // update table1 set content=@filecontent where filename=@fn // end // else // begin // insert table1 (filename,content) values(@fn,@filecontent) // end _bstr_t bstrSP("{CALL insert_update_blob(?,?)}" ); try { _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR); ADODB::_StreamPtr adostream; adostream.CreateInstance(_T("ADODB.Stream")); adostream->Type = ADODB::adTypeBinary; adostream->Open(varOptional,ADODB::adModeUnknown, ADODB::adOpenStreamUnspecified, _T(""), _T("")); adostream->LoadFromFile("C://masterz//20041229.rar"); _variant_t vReadTo = adostream->Read(ADODB::adReadAll); long blob_size = adostream->GetSize(); adostream->Close(); _bstr_t bstrEmpty; Conn1.CreateInstance( __uuidof( ADODB::Connection ) ); Cmd1.CreateInstance( __uuidof( ADODB::Command ) ); Conn1->ConnectionString = bstrConnect; Conn1->Open( bstrConnect, bstrEmpty, bstrEmpty, -1 ); Cmd1->ActiveConnection = Conn1; Cmd1->CommandText = bstrSP; Cmd1->CommandType = ADODB::adCmdText; Conn1->Properties->Refresh(); inParam = Cmd1->CreateParameter(_bstr_t("@fn"),ADODB::adChar,ADODB::adParamInput,2,_variant_t( "a" )); Cmd1->Parameters->Append(inParam); blobParam = Cmd1->CreateParameter(_bstr_t("@filecontent"),ADODB::adLongVarBinary,ADODB::adParamInput,blob_size,vReadTo); Cmd1->Parameters->Append(blobParam); Cmd1->Properties->Refresh(); print_properties("Cmd1",Cmd1->Properties); Cmd1->Execute(NULL,NULL,ADODB::adExecuteNoRecords); Conn1->Close(); //select filename,datalength(content) from table1 where datalength(content)>0 } catch(_com_error &e) { _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); printf("/nCOM error occurred, Source : %s /n Description : %s /n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription); PrintProviderError(Conn1); } printf("/nprogram end/n"); return 0; } VOID PrintProviderError(ADODB::_ConnectionPtr pConnection) { ADODB::ErrorPtr pErr = NULL; long nCount = 0; long i = 0; if( (pConnection->Errors->Count) > 0) { nCount = pConnection->Errors->Count; for(i = 0; i < nCount; i++) { pErr = pConnection->Errors->GetItem(i); printf("/n/t Error number: %x/t%s", pErr->Number, (LPCSTR)pErr->Description); } } }
- 调用存储过程进行图片的插入或修改
- sql 查看最近修改的表或存储过程
- 自动生成对表进行插入和更新的存储过程的存储过程
- 自动生成对表进行插入和更新的存储过程的存储过程
- 自动生成对表进行插入和更新的存储过程的存储过程
- 自动生成对表进行插入和更新的存储过程的存储过程
- 自动生成对表进行插入和更新的存储过程的存储过程
- sql生成(插入、修改、删除数据的存储过程)代码的存储过程
- c#调用带参数或返回值的存储过程
- JDBC回顾四CallableStatement进行存储过程的调用
- java端进行存储过程的简单调用
- 插入 修改 删除 查询 存储过程
- luasql-master的修改,支持调用存储过程
- 应用程序调用存储过程插入数据。
- OCCI调用存储过程实现批量插入
- OCCI调用存储过程实现批量插入
- 存储过程或自定义函数调用存储过程的变通实现方法
- SQL存储过程(CLR存储过程)或函数中调用.NET程序集中的方法
- C#中的类型转换
- 项目开发计划书节选
- 请问哪里可以下载TS流编解码的东东?
- web.config加密某个配置节
- 身份证号码验证-支持新的带x身份证
- 调用存储过程进行图片的插入或修改
- windows命令合集
- 日常用语--见面交谈
- IText入门必读
- VC下加载JPG/GIF/PNG图片的两种方法
- 在一个线程中产生多个线程
- 注册表根键
- 使用asp.net将图片上传并存入SqlServer中,然后从SqlServer中读取并显示出来
- java抽取word,pdf的四种武器