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.

Re: DataGridView and Database Problem 80 80

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

Re: DataGridView and Database Problem 80 80

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

Re: DataGridView and Database Problem 80 80

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

Re: DataGridView and Database Problem 80 80

@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() + "#"
Re: DataGridView and Database Problem 80 80

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

Re: DataGridView and Database Problem 80 80

yes you are right so your problem is solved?

Re: DataGridView and Database Problem 80 80

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

Re: DataGridView and Database Problem 80 80

Yeah Solved.. Thanks a lot..

Re: DataGridView and Database Problem 80 80

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;
Re: DataGridView and Database Problem 80 80

Okay I will..

Be a part of the DaniWeb community

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