I have this function on my C# project
public DataTable access2dt()
{
string myConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=test.accdb";
using (var con = new OleDbConnection(myConnectionString))
{
con.Open();
using (var cmd = new OleDbCommand("EXEC OUTBOUND_FILTER",con))
{
cmd.Parameters.AddWithValue("prmORIGINCODE", "BDO");
cmd.Parameters.AddWithValue("prmORIGIN", "\"*\"");
cmd.Parameters.AddWithValue("prmSERVICECODE", "REG15");
cmd.Parameters.AddWithValue("prmDESTCODE", "AMI");
cmd.Parameters.AddWithValue("prmDESTINATION", "\"*\"");
using (OleDbDataReader rdr = cmd.ExecuteReader())
{
DataTable myTable = new DataTable();
myTable.Load(rdr);
return myTable;
}
}
}
}
the function above is for execute query object in Ms Access with some parameter, the code just works for my project but i have problem with "code style".
I want to change the code so while i have another query WITH another different parameter i don't need to rewrite that code (see the parameter, query name and db file name is "hard-coded" to function).
Any suggestion and C# code will be helpfull.