为什么我有时候使用
strSQL="select * from UserInformation where PhoneNumber="+m_phonenumber);时会提示错误,改成下面的形式后才正常运行,有时又不用改.也可以正常运行.
strSQL.Format("select * from UserInformation where PhoneNumber='%s'",m_phonenumber);
觉得有些奇怪,想请大家分析下原因.

解决方案 »

  1.   

    [Quote=引用楼主 redleaf515 的帖子:]
    为什么我有时候使用 
    strSQL="select * from UserInformation where PhoneNumber="+m_phonenumber);时会提示错误,改成下面的形式后才正常运行,有时又不用改.也可以正常运行. 
    strSQL.Format("select * from UserInformation where PhoneNumber='%s'",m_phonenumber); 
    觉得有些奇怪,想请大家分析下原因.
    [/Quo]
    前面的写法 相当于CString str="xxx"+str2;
    事实上要求前一个必须是CString类型
    后者则没有问题,建议统一使用后者。