形成一个对数据库进行读操作的字符串,要求ArticleId between beginindex and endindex,
beginindex,endindex是变量
char * select =new char[1000];
memset(select,0,sizeof(select));
char *firstpart="select CKeyWord,ArticleId,CAbstract from Article where ArticleId between ";
char *lastpart=" order by ArticleId";
char middlepart1[100];
char middlepart2[100];
sprintf_s(middlepart1,sizeof(middlepart1),"%d",beginindex);
sprintf_s(middlepart2,sizeof(middlepart2),"%d",endindex);
strcat(select,firstpart);
strcat(select,middlepart1);
strcat(select," and ");
strcat(select,middlepart2);
strcat(select,lastpart);
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=***;Persist Security Info=True; User ID=sa;Initial Catalog=ArticleCollection";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute(select,NULL,adCmdText);
delete []select
以下是我的方法,不知各位大侠有什么更好的方法吗?
各位大侠还有什么更好的方法?
隐约记得以前学MFC,看孙鑫的视频,里面有个例子,好像是3+4=5,但是从书上找不到了,好像是用的CString 的format,如何用了CString的format,还可以转化成string吗?》
sprintf_s(select,1000,"%s %d and %d %s",firstpart,beginindex,endindex,lastpart);
CString vstring;
vstring.Format(
"select CKeyWord,ArticleId,CAbstract from Article where ArticleId between %d and %d ",
beginindex,endindex);