C++Builder之数据库ADO组件-TADOStoredProc学习
前言:C++Builder的资料相对较少,查了很多都是Delphi的,最终还是查资料摸索出来了,完整记录在此,共享给需要的人。
废话不说,代码如下:
String __fastcall TForm1::GetModelNumber(String SN)
{
//数据库连接字符串
String StrConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=Root;Password=888;Initial Catalog=Test_Prod;Data Source=Ado\\CES";
sp1->ConnectionString = StrConnect;
sp1->ProcedureName = "IPC_FindItemCode"; //存储过程名
SN = "12345600003";
sp1->Parameters->CreateParameter(L"SN", ftString, pdInput, 50, fgUnassigned);
sp1->Parameters->CreateParameter(L"ProjectName", ftString, pdReturnValue, 200, fgUnassigned);
sp1->Parameters->ParamByName(L"SN")->Value = SN;
sp1->Close();
sp1->ExecProc();
String sRet = VarToStr(sp1->Parameters->ParamByName(L"ProjectName")->Value);
return sRet;
}
数据库使用的是SQL Server.
其中Parameters
方法CreateParameter()第二个参数:参数类型,设置参考Delphi,毕竟同一种风格。
参考文献
【C Builder的ADO组件(精品)】
还没有评论,来说两句吧...