views:

176

answers:

1

Hello,
I have a database (MDB, Access) and I connect it to my program using an OLE object, now I have in the db a column filled with dates (ddmmyy),

I want to search and view (in Data grid view) all the fields that has a date before a Specific Date that I define .

the code of search that I used is :

 SQLstr = "SELECT * FROM tb WHERE anomber = '" & TextBox1.Text & "'"

What do I have to do?. Thanks.

+1  A: 

use the parameters to pass the date to the query, it's more saver(no sql injection) and more perfect(it will convert the date format to the correct format)

SQLstr = "SELECT * FROM tb WHERE anomber < ?"
Command.Parameters.Add(New OleDbParameter("@anomber", TextBox1.Text))
Command.CommandText = SQLstr

Edit: if the anomber field is the date field so the user can use < instead of =.

the OP question not clear about what he wants.

Edit2: after executing the command you should assign the results to the grid that you are using to display the data.

Wael Dalloul
This won't search the database for records that has a date which is prior to the search date, which the OP wants.
Moayad Mardini
I mean a have a column with dates , and I have a date in my program (x date) , and want to view all the fields that have any date before this date(x date)
Eias.N
Good edit, downvote cast.
Moayad Mardini
what I have to add instead of "Command.Parameters" , I don't know , please
Eias.N