1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| void Main()
{
HashTable selectParams = new HashTable();
selectParams.Add("@var1", "value1");
selectParams.Add("@var2", 2);
try
{
DataTable dt = GetMyDatas(selectParams);
}
catch (Exception ex)
{
throw ex
}
}
void GetMyDatas(HashTable dataParams)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("SELECT *"):
sb.AppendLine("FROM .....");
//... avec toute la requête ...//
try
{
GetDataTableFromQuery(sb.ToString(), HashTable dataParams);
}
catch (Exception ex)
{
throw ex;
}
}
void GetDataTableFromQuery(string SQL, HashTable SQLParams)
{
OleDbConnection con = new OleDbConnection("ConnectionString pour Access, mais dans un fichier de config :D");
con.Open();
OleDbCommand command = new OleDbCommand(SQL, con);
//... et tout le blabla pour génrer les paramètres avec Access ...//
try
{
adapter.Fill(table);
}
catch (Exception ex)
{
throw ex;
}
return table;
} |
Partager