用MFC实现odbc,遇到一点查询的sql的语法问题:
对一个表的若干列查询,
CString strSQL,str3,str4.....;
strSQL.Format("select 列1,列2,列3 from 表1 where 列4=‘%s' and 列5='%s'",str1,str2);(str1,str2为获得的字符变量)
m_pSet->Open(CRecordset::forwardOnly,strSQL);
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列1",str3);
m_pSet->GetFieldValue("列2",str4);
.........
}
..................
但是为什么每次出现错误,是sql语法的。我把sql的语句改为:
“select 列1 from 表1 where 列4=’。。”
就没有了错误,请问各位高手,sql的多列查询的语句该如何处理?
对一个表的若干列查询,
CString strSQL,str3,str4.....;
strSQL.Format("select 列1,列2,列3 from 表1 where 列4=‘%s' and 列5='%s'",str1,str2);(str1,str2为获得的字符变量)
m_pSet->Open(CRecordset::forwardOnly,strSQL);
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列1",str3);
m_pSet->GetFieldValue("列2",str4);
.........
}
..................
但是为什么每次出现错误,是sql语法的。我把sql的语句改为:
“select 列1 from 表1 where 列4=’。。”
就没有了错误,请问各位高手,sql的多列查询的语句该如何处理?
呵呵,你的SQL语句里面的逗号是中文字符!
strSql= "select 列1,列2,列3 from 表1 where 列4="