ADO 存储过程

1.ADO连接
CAdoConnection adoCn;
 CAdoRecordSet adoRs(&adoCn);
 if(!adoCn.ConnectSQLServer(this->m_strDBSrc,this->m_strDBName,this->m_strDBUserid,this->m_strDBPwd))
  return FALSE;
// "192.168.0.4",数据库名,登录验证的用户名,用户密码

 int iStoreID = pXml->SelectSingleNode("root/head/store_id")->GetInt();
 int iUserID = pXml->SelectSingleNode("root/head/user_id")->GetInt();

//2存储的初始与参数传值 
CAdoCommand adoCmd(&adoCn,"ReSendInfoCue");
 adoCmd.GetParameters()->Refresh();

None.gifadoCmd.GetParameters()->Refresh() 这句一定要有。否则存储没有做执行


 //@seqID int , --消息ID
 adoCmd.GetParameter(1)->Value = seqID ;
 adoCmd.GetParameter(2)->Value = iStoreID;
 adoCmd.GetParameter(3)->Value = iUserID;
//注:赋值的顺序要与存储过程一致 。参数数据类型的一致性转化如下

1 None.gif 1  存储过程的参数为int,tinyint
2 None.gifCString 转化为int 如:atoi(str.GetBuffer())
3 None.gif int  直接赋值
4 None.gif 2  存储过程的参数类型为nvarchar()
5 None.gifCString 的转化,如_variant_t((LPCTSTR)strInfo);
6 None.gif 3  存储过程的参数类型为datetime
7 None.gifCString 的转化为,如_variant_t((LPCTSTR)strTime)
8 None.gif因为在SQLDB中,时间类型衩看做是CString.
9 None.gif如,datetime  = 1998 - 12 - 21   11 : 11 : 20



//3 存储的执行与记录集的获取
 _RecordsetPtr pAdoRsMat = NULL;
 pAdoRsMat = adoCmd.Execute(adCmdStoredProc);
 if(pAdoRsMat == NULL)
  return FALSE;

 adoRs = pAdoRsMat;//返回记录集
 pXml->ClearEles(pXml->SelectSingleNode("root/data"));
 CString strInfo = "";
 CString strURL = "";
 CString strReatyCode,strStoreID,strEvent,strUserID;
 int nCnt = 0;// 不能用 adoRs.GetRecordCount();
//4记录集的读取
 if(adoRs.IsBOF() && adoRs.IsEOF())//判断是否是空记录集,若无这句判断,单下面while时,空记录集时会出错
     nCnt = 0;
 else

ContractedBlock.gif ExpandedBlockStart.gif
adoRs.MoveFirst();/*****要慎用,若前面有使用了if(adoRs.IsBOF() && adoRs.IsEOF())则不能使用!!~否则会出现下面的while读取语句值为空的情况!!


 while(!adoRs.IsEOF())
 { 
 adoRs.GetCollect("EventID",strEvent);
 adoRs.GetCollect("ReatyCode",strReatyCode);
 adoRs.GetCollect("Content",strInfo);
 adoRs.GetCollect("URL",strURL);
 adoRs.GetCollect("StoreID",strStoreID);
 adoRs.GetCollect("UserID",strUserID);
 nCnt++;
 adoRs.MoveNext();
 }

转载于:https://www.cnblogs.com/paopao/archive/2006/08/21/482579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值