Where子句不适用于OleDb c#

时间:2016-03-10 11:59:39

标签: c# ms-access oledb oledbcommand

此代码不起作用。我错了什么

                conn.Open();
                var cmd = new OleDbCommand();
                cmd.CommandText = String.Format("Select E.c_Date, E.c_Time, E.l_UID from tEnter E left join tuser U on E.l_UID=U.l_ID where E.c_Date>=@fromDate and E.c_Date<=@toDate");
                //cmd.CommandText = String.Format("Select E.c_Date, E.c_Time, E.l_UID from tEnter E where E.c_Date = '20160310'");
                //cmd.CommandText = String.Format("Select E.c_Date, E.c_Time, E.l_UID from tEnter E left join tuser U on E.l_UID=U.l_ID where E.c_Date>='{0}' and E.c_Date<='{1}'", sd, ed);
                //cmd.CommandText = String.Format("select* from tEnter");
                cmd.Parameters.Add("@fromDate", OleDbType.VarChar);
                cmd.Parameters["@fromDate"].Value = sd;

                cmd.Parameters.Add("@toDate", OleDbType.VarChar);
                cmd.Parameters["@toDate"].Value = ed;

                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                OleDbDataReader reader = cmd.ExecuteReader();

当我添加where子句时,它不起作用。但对于查询字符串,它正在工作cmd.CommandText = String.Format("select* from tEnter"); 也在工作Select E.c_Date, E.c_Time, E.l_UID from tEnter E

0 个答案:

没有答案