我想构建一个查询语句,哪儿错了,VS2008 VC++ MFC ?
CStringstrSql=(_bstr_t)"select*fromProductwhere1=1";if(str_ProName){strSql=strSql+(_b...
CString strSql = (_bstr_t)"select * from Product where 1=1";
if(str_ProName)
{
strSql =strSql + (_bstr_t)("and proName = ")+(_bstr_t)str_ProName;
}
if(str_ProZhi)
{
strSql =strSql + (_bstr_t)("and proZhi = ")+(_bstr_t)str_ProZhi;
}
if(str_FengZhuang)
{
strSql =strSql + (_bstr_t)("and proFengZhuang = ")+(_bstr_t)str_FengZhuang;
}
str_XXX 为控件变量
调用
vector<vector<_variant_t>> vResult(m_DataBase.Select(strSql.AllocSysString(), vName)); 展开
if(str_ProName)
{
strSql =strSql + (_bstr_t)("and proName = ")+(_bstr_t)str_ProName;
}
if(str_ProZhi)
{
strSql =strSql + (_bstr_t)("and proZhi = ")+(_bstr_t)str_ProZhi;
}
if(str_FengZhuang)
{
strSql =strSql + (_bstr_t)("and proFengZhuang = ")+(_bstr_t)str_FengZhuang;
}
str_XXX 为控件变量
调用
vector<vector<_variant_t>> vResult(m_DataBase.Select(strSql.AllocSysString(), vName)); 展开
1个回答
展开全部
CString strSql = (_bstr_t)"select * from Product where 1=1";
if(str_ProName)
{
这里应该有空格 没有的话就是1and
strSql =strSql + (_bstr_t)(" and proName = ")+(_bstr_t)str_ProName;
}
if(str_ProZhi)
{
这里也应该有空格 and前 下边的也一样
strSql =strSql + (_bstr_t)(" and proZhi = ")+(_bstr_t)str_ProZhi;
}
if(str_FengZhuang)
{
strSql =strSql + (_bstr_t)(" and proFengZhuang = ")+(_bstr_t)str_FengZhuang;
}
if(str_ProName)
{
这里应该有空格 没有的话就是1and
strSql =strSql + (_bstr_t)(" and proName = ")+(_bstr_t)str_ProName;
}
if(str_ProZhi)
{
这里也应该有空格 and前 下边的也一样
strSql =strSql + (_bstr_t)(" and proZhi = ")+(_bstr_t)str_ProZhi;
}
if(str_FengZhuang)
{
strSql =strSql + (_bstr_t)(" and proFengZhuang = ")+(_bstr_t)str_FengZhuang;
}
追问
你说的这是sql语法错误,不过现在是sql构建不成功。
追答
你报错信息是什么!贴出来看看!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询