InfernumDeus
InfernumDeus

Reputation: 1202

Ms Access. System.Data.OleDb.OleDbException: No value given for one or more required parameters

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.

Upvotes: 1

Views: 1362

Answers (2)

Shankar
Shankar

Reputation: 256

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);

Upvotes: 1

Gustav
Gustav

Reputation: 55841

Try with this:

"SELECT * FROM TableName WHERE Date Between ? and ?"

Upvotes: 1

Related Questions