Problem is based on C#, ADO.NET, using Access Database.
I am trying to filter the results from the database and display them in DataGridView on click of 'button1' button. But the datagridview shows empty results when there are actually 3 records with matching conditions. According to what I know, the SQL statement is right, I am not able to find what mistake I am making.
I have attached the whole project and database, problem is in dispAndEdit form.

Edited by guru_iyer: spelling mistake

5 Years
Discussion Span
Last Post by guru_iyer

i have checked your code but it is giving datatype mismatch exception. Anyway in my opinion instead of using

"select * from " + dlrName + " where date1 between  @date1 and @date2"

you may use

"select * from " + dlrName + " where date1 >='"dateTimePicker1.Value.ToString()"' and date1 >= '"dateTimePicker2.Value.ToString()"'"

it may help you and also will reduce your code of converting your date two times

Edited by abelLazm: n/a


@abelLazm it still shows DataType Mismatch at Line 49...

Edited by guru_iyer: Line of error


ok so you are also having the same exception can you give me some time i am checking it again.. have you checked the details of OLEDBADAPTOR class? because exception is coming there.. Anyway Let me check :)


@abel Put # instead of ' in the program. I think it removes error..

"select * from " + dlrName + " where date1 >=#" + dateTimePicker1.Value.ToString() + "# and date1 >= #" + dateTimePicker2.Value.ToString() + "#"

Yeah I got it... Your answer was right.. Thanks..

"select * from " + dlrName + " where date1 >=#" + dateTimePicker1.Value.ToString() + "# and date1 [U]<=[/U] #" + dateTimePicker2.Value.ToString() + "#"

You made a Mistake in underlined part


remove these lines from your code to make it generic :)

// dateTimePicker1.Value = Convert.ToDateTime("01/04/2011");
            //dateTimePicker2.Value = Convert.ToDateTime("06/06/2011");
           // dateTimePicker1.Format = DateTimePickerFormat.Short;
           // dateTimePicker2.Format = DateTimePickerFormat.Short;

Edited by abelLazm: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.