| 12
 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
 52
 53
 54
 55
 
 |  
static class QueryManager
(
private static SqlConnection _connection = null;
private static string _connectionString = "database=xxxxx;...";
	public static DataSet GetDataResults(string query)
	{
		DataSet dts = null;
 
			try
			{
				if (_connection == null) 
				     _connection = new SqlConnection(_connectionString);
				if(_connexion.State != Open) 
				     _connexion.Open();
 
				SqlCommand cmd = _connexion.CreateCommand();
				cmd.CommandText = query;
				cmd.CommandTimeout = 180;
 
				SqlDataAdapter adpt = new SqlDataAdapter(cmd);
				DataSet dts = new DataSet();
				adpt.Fill(dts);
			}
			catch 
			{
				 // gestion des erreurs
			}
 
		return dts;
	}
 
        public static bool ExecuteQuery(string query)
        {
                bool success = false;
                try
			{
				if (_connection == null) 
				     _connection = new SqlConnection(_connectionString);
				if(_connexion.State != Open) 
				     _connexion.Open();
 
				IDbCommand cmd = _connexion.CreateCommand();
				cmd.CommandText = query;
				cmd.CommandTimeout = 180;
 
				success = cmd.ExecuteQuery() > 0;
			}
			catch 
			{
				 // gestion des erreurs
			}
                return success;
        }
} | 
Partager