I create SelectCommand this way:
OleDbCommand SelectCommand = new OleDbCommand(
"SELECT * FROM TableName WHERE Date Between dt_begin = ? and dt_end = ?", connection);
SelectCommand.Parameters.Add("dt_begin", OleDbType.Date).Value = new DateTime(2015, 6, 1);
SelectCommand.Parameters.Add("dt_end", OleDbType.Date).Value = new DateTime(2015, 6, 31);
After execution of this command i get error:
System.Data.OleDb.OleDbException (0x80040E10): No value given for one or more required parameters.
First parameter gets 01.06.2015. Second - 30.06.2015. Not sure in date format, but if it's wrong, i will get corresponding error. Date is a column name.
So, what can be wrong? I mean, here is two parameters and both is defined.
试试这个:
"SELECT * FROM TableName WHERE Date Between ? and ?"
You can also create complete SQL string instead of parameters. like,
OleDbCommand SelectCommand = new OleDbCommand(
"SELECT * FROM TableName WHERE Date Between '" + DateTime.Now.ToString("yyyy-MM-dd") + "' and '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + "'", connection);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.