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字符串解析成函数
this.myConnection = new OleDbConnection(strConnection);
this.da = new OleDbDataAdapter(Sql,this.myConnection);
this.ds.Clear();
this.da.Fill(ds,tempTableName);报错信息为:表达式中'FormatDateTime'函数未定义..请那位帮我解决一下,C#为什么把这个SQL字符串解析成函数
顺便说一下,在SQL中尽量不要在条件的字段上使用函数,影响速度,而应该对传入的变量进行格式化,比如你那个txt1可以转化为日期格式,这样速度会快一
可以写成:
string Sql = "SELECT * FROM sms_msgsend where msg_sendstatus ='" +txt2+ "' and "
+
FormatDateTime(msg_sendtime,2)
+
"='" +txt1+ "'";