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.

Recommended Answers

All 10 Replies

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

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

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

yes you are right so your problem is solved?

Most probably.. I'll have look once again..

Yeah Solved.. Thanks a lot..

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;

Okay I will..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.