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 52 53 54 55
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Npgsql;
using System.Data.OleDb;
namespace MAJBDD
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
NpgsqlConnection connexionPostgreSQL = new NpgsqlConnection();
connexionPostgreSQL.ConnectionString = "Server=IPServeur;Port=PostServeur;User Id=utilisateur;Password=pass;Database=db";
OleDbConnection connexionAccess = new OleDbConnection();
connexionAccess.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= cheminMdb";
NpgsqlCommand PostGreSQLCommand = new NpgsqlCommand("SELECT * FROM employes", connexionPostgreSQL);
OleDbCommand AccessSQLCommand = new OleDbCommand("SELECT [Tbl Employes].ID AS id, [Tbl Employes].Nom AS nom, [Tbl Employes].Prenom AS prenom, [Tbl Employes].Adresse AS adresse, [Tbl Employes].Ville AS ville, [Tbl Employes].Province AS province, [Tbl Employes].[Code Postal] AS code_postal, [Tbl Employes].Telephone AS telephone, [Tbl Employes].Courriel AS courriel, [Tbl Employes].Naissance AS naissance, [Tbl Employes].Nas AS nas, [Tbl Employes].Statut AS statut, [Tbl Employes].Division AS division, [Tbl Employes].[Date Embauche] AS date_embauche, [Tbl Employes].Taux AS taux, [Tbl Employes].[Historique Taux] AS historique_taux, [Tbl Employes].Password AS mot_de_passe, [Tbl Employes].Code AS code, IIf([Tbl Employes]![Actif]=Yes,1,0) AS actif, IIf([Tbl Employes]![Supprimer]=Yes,1,0) AS supprimer, Format([Tbl Employes]![Date],'yyyy/mm/dd hh:nn') AS date_derniere_maj, [Tbl Employes].[Taux Facturable] AS taux_facturable, IIf([Tbl Employes]![ChargeProjet]=Yes,1,0) AS charge_projet, IIf([Tbl Employes]![ChefEquipe]=Yes,1,0) AS chef_equipe, IIf([Tbl Employes]![ParHeure]=Yes,1,0) AS par_heure, IIf([Tbl Employes]![Terrain]=Yes,1,0) AS terrain" +
" FROM [Tbl Employes]", connexionAccess);
OleDbDataAdapter DataAdapter_Access_employes = new OleDbDataAdapter(AccessSQLCommand);
NpgsqlDataAdapter DataAdapter_PostgreSQL_employes = new NpgsqlDataAdapter(PostGreSQLCommand);
NpgsqlCommandBuilder CommandBuilderPgSQLEmployes = new NpgsqlCommandBuilder(DataAdapter_PostgreSQL_employes);
DataSet DataSet_Employes = new DataSet();
try
{
DataAdapter_Access_employes.AcceptChangesDuringFill = false;
DataAdapter_Access_employes.Fill(DataSet_Employes,"employes");
DataAdapter_PostgreSQL_employes.Fill(DataSet_Employes, "PgEmployes");
DataGridView_AccessEmployes.DataSource = DataSet_Employes.Tables["employes"];
dataGridView_PostgreSQL.DataSource = DataSet_Employes.Tables["PgEmployes"];
DataAdapter_PostgreSQL_employes.Update(DataSet_Employes, "PgEmployes");
DataSet_Employes.AcceptChanges();
}
catch (Exception ex)
{
MessageBox.Show(this,ex.Message, "Connexion error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
} |
Partager