ghilas

ghilas

  • NA
  • 1
  • 1.2k

Insert from access to oracle

May 31 2012 8:52 AM
hi,
i have a problem when i insert from access to oracle and this is my code:

  //**************************** connexion à la base de données Access ***************************
  #region Connexion à la base de données Access
  OleDbConnection connectAcc = new OleDbConnection();
  connectAcc.ConnectionString = ConfigurationManager.ConnectionStrings["oConnectionString"].ConnectionString;
  connectAcc.Open();
  #endregion

  //**************************** connexion à la base de données Oracle ****************************
  #region Connexion à la base de données OracleClient
  string ConnString = "Data Source=(DESCRIPTION="

  + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=siege-dba-rct)(PORT=1521)))"

  + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SIGTST)));"

  + "User Id=SIG_ANALYSE;Password=SIG;";

  OracleConnection connectOrcl = new OracleConnection(ConnString);
  connectOrcl.Open();
  #endregion

  #region Requete Oracle

  //connectOrcl.Open();
  //string queryString =
  //  "INSERT INTO ETAT_ACTUEL_REGARD (ID_REGARD, DIAM_REG) values (0, 'HUSSEIN DEY....')";

  //OracleCommand command = new OracleCommand(queryString);
  //command.Connection = connectOrcl;
  //command.ExecuteNonQuery();
  //connectOrcl.Close();

  #endregion

  #region Requete Access

  //connectAcc.Open();
  //string queryString1 = "SELECT ID_REGARD from ENCRASS";
  //  //"INSERT INTO REHAUSSE (ID_REGARD) values (16561083)";
  //OleDbCommand cmd = new OleDbCommand();
  //cmd.CommandText = queryString1;
  //cmd.Connection = connectAcc;
  //cmd.ExecuteNonQuery();


  #endregion

  #region Requet de selecion

  //connectAcc.Open();
  //string querystring2 =
  //  "SELECT top 1 * from ENCRASS";
  //OleDbCommand cmd1 = new OleDbCommand();
  //cmd1.CommandText = querystring2;
  //cmd1.Connection = connectAcc;
  //cmd1.ExecuteNonQuery();
  //connectAcc.Close();

  #endregion

  #region Requêt de Chargement

  string querystring3, queryString1;

  queryString1 =
 "select ID_REGARD,CENTRE,COMMUNE,ACC_REG,RELEVE,DEBIT,TRAFIC,METEO,TYPE_TAMPN,ENC_AGENT,ENC_OBSRVT,EAU_CLAIRE,NAT_DEPOT,PROF_REG,ENC_REG,ACC_REG,CENTRE,ENC_DATE,ACC_VEHCLE from ENCRASS";

  OleDbCommand cmd = new OleDbCommand(queryString1);
  cmd.Connection = connectAcc;
  OleDbDataReader reader = cmd.ExecuteReader();

  while (reader.Read())
  {
  string Var_CENTRE,
  Var_ID_REGARD,
  Var_ENC_DATE,
  //  Var_ZONE,
  Var_COMMUNE,
  Var_ACC_REG,
  Var_RELEVE,
  Var_DEBIT,
  Var_TRAFIC,
  Var_METEO,
  Var_TYPE_TAMPN,
  Var_ENC_AGENT,
  Var_ENC_OBSRVT,
  Var_EAU_CLAIRE,
  Var_NAT_DEPOT,
  Var_PROF_REG,
  Var_ENC_REG,
  Var_ACC_VEHCLE;

  Var_ID_REGARD = reader["ID_REGARD"].ToString();
  Var_CENTRE = reader["CENTRE"].ToString();
  Var_ENC_DATE = reader["ENC_DATE"].ToString();
  // Var_ZONE = reader["ZONE"].ToString();
  Var_COMMUNE = reader["COMMUNE"].ToString();
  Var_ACC_REG = reader["ACC_REG"].ToString();
  Var_RELEVE = reader["RELEVE"].ToString();
  Var_DEBIT = reader["DEBIT"].ToString();
  Var_TRAFIC = reader["TRAFIC"].ToString();
  Var_METEO = reader["METEO"].ToString();
  Var_TYPE_TAMPN = reader["TYPE_TAMPN"].ToString();
  Var_ENC_AGENT = reader["ENC_AGENT"].ToString();
  Var_ENC_OBSRVT = reader["ENC_OBSRVT"].ToString();
  Var_EAU_CLAIRE = reader["EAU_CLAIRE"].ToString();
  Var_NAT_DEPOT = reader["NAT_DEPOT"].ToString();
  Var_PROF_REG = reader["PROF_REG"].ToString();
  Var_ENC_REG = reader["ENC_REG"].ToString();
  Var_ACC_VEHCLE = reader["ACC_VEHCLE"].ToString();

  querystring3 =
  "insert into ETAT_ACTUEL_REGARD_TST (ID_REGARD,CENTRE,COMMUNE,ACC_REG,RELEVE,DEBIT,TRAFIC,METEO,TYPE_TAMPN,ENC_AGENT,ENC_OBSRVT,EAU_CLAIRE,NAT_DEPOT,PROF_REG,ENC_REG,ENC_DATE,ACC_VEHCLE) values (" + Var_ID_REGARD + ",'" + Var_CENTRE + "','" + Var_COMMUNE + "','" + Var_ACC_REG + "','" + Var_RELEVE + "','" + Var_DEBIT + "','" + Var_TRAFIC + "','" + Var_METEO + "','" + Var_TYPE_TAMPN + "','" + Var_ENC_AGENT + "','" + Var_ENC_OBSRVT + "','" + Var_EAU_CLAIRE + "','" + Var_NAT_DEPOT + "'," + Var_PROF_REG + "," + Var_ENC_REG + ",'" + Var_ENC_DATE + "','" + Var_ACC_VEHCLE + "')";

  OracleCommand command = new OracleCommand(querystring3);
  command.Connection = connectOrcl;
  command.ExecuteNonQuery();
 
  }// fin de la boucle while
 
  reader.Close();
  connectOrcl.Close(); //Déconnexion de la base de données OracleClient
  connectAcc.Close(); //Déconnexion de la base de données Access

 
  #endregion
 
  return "Vous êtes Connecté";

  }


  catch (Exception ex)
  {
 
  return ex.Message;

  }

  }
  }
}