日期:2014-05-17  浏览次数:20742 次

ADO中的这个查询语句怎么又错误呢?求解释~~~
sql.Format("select tb_student_information.student_number, \
tb_student_information.student_name,tb_student_information.student_class, \
tb_student_answered.question_number,tb_student_answered.question_cishu, \
tb_student_answered.times, tb_student_answered.submit_time,\
tb_student_answered.score from tb_student_information, \
tb_student_answered where tb_student_information.student_number=\
tb_student_answered.student_number and tb_student_answered.score!=\'%s\' \
and tb_student_information.student_class=\'%s\' \
and tb_student_answered.question_cishu=\'%s\'", "0", class_name, times);
//执行sql语句
pRecordset->Open((_variant_t)sql,
pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);


------解决方案--------------------
报错内容呢。。。。。。。。。。。
------解决方案--------------------
C# code

sql.Format("select ta.student_number,"+              //c#里面字符串拼接用 + 号
                   ta.student_name,ta.student_class,"+
                   tb.question_number,tb.question_cishu,"+
                   tb.times,d.submit_time,"+
                   tb.score 
              from tb_student_information ta,"+       //当表名过长时,最好个表取个别名
                   tb_student_answered tb 
             where ta.student_number=tb.student_number"+
               and tb.score not like \'%s\'"+          //oracle里面模式匹配使用like而不用!=号
               and ta.student_class not like \'%s\'"+
               and tb.question_cishu like \'%s\'", "0", class_name, times);

------解决方案--------------------
C# code

--字符串拼接,要注意双引号和转移字符的使用
sql.Format("select ta.student_number,"+              //c#里面字符串拼接用 + 号
                  "ta.student_name,ta.student_class,"+
                  "tb.question_number,tb.question_cishu,"+
                  "tb.times,d.submit_time,"+
                  "tb.score 
             "from tb_student_information ta,"+       //当表名过长时,最好个表取个别名
                  "tb_student_answered tb 
            "where ta.student_number=tb.student_number"+
              "and tb.score not like \'%s\'"+          //oracle里面模式匹配使用like而不用!=号
              "and ta.student_class not like \'%s\'"+
              "and tb.question_cishu like \'%s\'", "0", class_name, times);

------解决方案--------------------
trace program step by step。