我已经知道怎么参数化了,现在就是对like语句不知道怎么参数化了,知道的给分。 pCmd->CommandText = _T("select * from stu where id=? and name like '%?%'"); param = pCmd->CreateParameter(_T(""), adInteger, adParamInput, sizeof(int), _variant_t((int)3)); pCmd->Parameters->Append(param); param = pCmd->CreateParameter(_T(""), adVarChar, adParamInput, 50, _variant_t(_T("w"))); pCmd->Parameters->Append(param); pRec = pCmd->Execute(NULL, NULL, adCmdText);
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL; sParm1 = "3"; sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'";
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL; sParm1 = "3"; sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'"; 你这个是一般的拼凑,并没有参数化。
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL; sParm1 = "3"; sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'"; 你这个是一般的拼凑,并没有参数化。确实是这样的。但,技术是用来解决问题的,而不在于用何种技术解决问题。你学C(这只是一个比方,当然,需要的话,你也可以换成另一个例子,比如C++),甚至大部份学过C的人,可能都写过一个"hello world",但你绝不需要知道"hello world 的 100种写法"具体到计算机技术,它可能就是时间和空间成本的问题。为什么必须纠结于到达山顶是走路过去,还是自己发明一个飞机上去呢?仅仅因为上山的那一刻,你帅一点?还是,老师要求我造颗原子弹去打蚊子?
pCmd->CommandText = _T("select * from stu where id=? and name like '%?%'"); ==> pCmd->CommandText = _T("select * from stu where id=? and name like ?"); 通配符在参数中提供
你是不是可动态改变查询语句的条件,比如这次查姓名包括“AB”,下次要杳姓名包括“CD”,但还用一条查询语句,如果是这样,就这么做: CString str; CString SName; int ID; ID=10; SName="AB"; str.Format("select * from stu where id=%d and name like '%s'",ID,SName); ID=20; SName="ABCD"; str.Format("select * from stu where id=%d and name like '%s'",ID,SName);
pCmd->CommandText = _T("select * from stu where id=? and name like '%?%'");
param = pCmd->CreateParameter(_T(""), adInteger, adParamInput, sizeof(int), _variant_t((int)3));
pCmd->Parameters->Append(param);
param = pCmd->CreateParameter(_T(""), adVarChar, adParamInput, 50, _variant_t(_T("w")));
pCmd->Parameters->Append(param);
pRec = pCmd->Execute(NULL, NULL, adCmdText);
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL;
sParm1 = "3";
sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'";
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL;
sParm1 = "3";
sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'";
你这个是一般的拼凑,并没有参数化。
我也不知道,不过我是这样做的CString sParm1,sParm2,YourSQL;
sParm1 = "3";
sParm2 = "abc'留意这里有单引号";sParm2.Replace("'","''")YourSQL = "select * from stu where id="+sParm1+" and name like '%"+sParm2+"%'";
你这个是一般的拼凑,并没有参数化。确实是这样的。但,技术是用来解决问题的,而不在于用何种技术解决问题。你学C(这只是一个比方,当然,需要的话,你也可以换成另一个例子,比如C++),甚至大部份学过C的人,可能都写过一个"hello world",但你绝不需要知道"hello world 的 100种写法"具体到计算机技术,它可能就是时间和空间成本的问题。为什么必须纠结于到达山顶是走路过去,还是自己发明一个飞机上去呢?仅仅因为上山的那一刻,你帅一点?还是,老师要求我造颗原子弹去打蚊子?
==>
pCmd->CommandText = _T("select * from stu where id=? and name like ?");
通配符在参数中提供
CString str;
CString SName;
int ID;
ID=10;
SName="AB";
str.Format("select * from stu where id=%d and name like '%s'",ID,SName);
ID=20;
SName="ABCD";
str.Format("select * from stu where id=%d and name like '%s'",ID,SName);