DateTime format in MS Access

i developed the module and saved the data in the MS Access database (mdb). One field uses the date name (Date_of_Installation) for reference. Records are saved in order. when I retrieve a record using OleDBDataAdaptor to populate a DataSet for a datetime problem, the format in the database changes to change the date and time format in the database. Request example

command.CommandText = "Select * from LicenseDetails where instr(1,"+ArgName+",'" + Value + "') and Date_of_Installation between #06/08/2009 1:31:10 PM# and #10/09/2009 2:54:57 PM#; 

I use the visual studio of 2005. How to use Linq?

+4
source share
1 answer

If I understand what you want to do, you want to populate the DataSet using the OleDb adapter for MS Access, and then filter out this DataSet with the request from above. It is right?

If so, then the date columns in the returned DataSet should contain DateTime types, and you should be able to simply query the DataSet using LINQ. Click here for an ADO.NET blog article on how to do this.

Your LINQ expression will look something like this:

 var query = from r in MyDataSet.Tables["LicenseDetails"].AsEnumerable() where r.Field<DateTime>("Date_of_Installation") >= new DateTime(6,8,2009,13,31,10) && r.Field<DateTime>("Date_of_Installation") <= new DateTime(10,9,2009,14,54,57) select r; 

FYI instr(1,"+ArgName+",'" + Value + "') returns int, which is the Value position in ArgName, starting at position 1, or zero if it is not found. If this data is passed as string literals, they will simply return zero, which is probably interpreted as false in the Where clause and does not return any results. If you want to get the position of a string inside another in C #, use string.IndexOf() , if you want to find out if one string contains another, use string.Contains() Also note that between..and in Access includes start / end points, like LINQ above.

+7
source

All Articles