string Sql = "SELECT * FROM sms_msgsend where msg_sendstatus ='" +txt2+ "' and  FormatDateTime(msg_sendtime,2)='" +txt1+ "'";
this.myConnection = new OleDbConnection(strConnection);
this.da = new OleDbDataAdapter(Sql,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);报错信息为:表达式中'FormatDateTime'函数未定义..请那位帮我解决一下,C#为什么把这个SQL字符串解析成函数

解决方案 »

  1.   

    sql语句里面的函数跟你代码里面的函数(方法)是不同的
      

  2.   

    FormatDateTime是什么,sql中没有这样的函数吧。C#肯定没有把FormatDateTime解析成函数。
      

  3.   

    SQL Server中没有FormatDateTime这个函数,所以会报错
    顺便说一下,在SQL中尽量不要在条件的字段上使用函数,影响速度,而应该对传入的变量进行格式化,比如你那个txt1可以转化为日期格式,这样速度会快一
      

  4.   

    //请那位帮我解决一下,C#为什么把这个SQL字符串解析成函数你这样写法,只有解析成函数,那你想解析成什么呢?
      

  5.   

    SQL字符串是数据库解析的,而不是C#程序~
      

  6.   

    string Sql = "SELECT * FROM sms_msgsend where msg_sendstatus ='" +txt2+ "' and  FormatDateTime(msg_sendtime,2)='" +txt1+ "'";
    可以写成:
    string Sql = "SELECT * FROM sms_msgsend where msg_sendstatus ='" +txt2+ "' and  "
    +
    FormatDateTime(msg_sendtime,2)
    +
    "='" +txt1+ "'";
      

  7.   

    SQL Server中没有FormatDateTime这个函数
      

  8.   

    在ACCESS数据中记录的是常规日期格式,但我的TXT2是个短日期格式,因此在比较时只有先通过转换才能正确得到结果.这个SQL语句我在ACCESS中测试是对了的