|
I am writing a small departmental DB using Access and C# Express as a front end. I am looking for some sample code to produce a query form with three parameter fields (similar to the following). The resulting query should filter all the values entered: ![]() ![]() ![]() Analyst: [ ] Client [ ] Status [ ] There does not seem to be a way to use LINQ for querying Access databases with SQL. Can anyone point me to a tutorial/sample code to do this using ADO.NET (or better method)? Thanks :-) Ian |
Loading



Bechir BejaouiPosted Dec 10, 2008, 3:06 PM
string SqlQuery = "Select * From Table Where Field1 = ? .... And Fieldn = ?";
using (OleDbConnection conn = new OleDbConnection("Microsoft.Jet.OleDb.4.0;Data Source=[Path]|Database.mdb"))
{
using (OleDbCommand cmd = new OleDbCommand(SqlQuery, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Field1", Value1);
.....................
cmd.Parameters.AddWithValue("Fieldn", Valuen);
try{
conn.Open();
using (OleDbDataReader reader = cmd.ExecuteReader())
{
//TO DO :leverage the code here to handle your data
//you can use a dataAdapter instead if you want work with the unconnected mode
}
} catch(Oledbexception caught){}
}
}
Bechir BejaouiPosted Dec 11, 2008, 6:15 AM
Ian KennedyPosted Dec 11, 2008, 3:50 AM
That's just what I was looking for :-)
If you ever need any questions answering on Computer Forensics.... ;-)