IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

insert via prepare sur base oracle


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 75
    Par défaut insert via prepare sur base oracle
    Bonjour à tous !

    Je cherche à faire un simple insert et après moult recherche, je ne trouve pas la solution du problème que voilà :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    string connectionString = "provider=MSDAORA;data source=DEV;user id=data;password=data";
    OleDbConnection myConnection = new OleDbConnection(connectionString);
    OleDbCommand myCommand = myConnection.CreateCommand();
    myConnection.Open();
    myCommand.CommandText = "insert into environ (nomEnviron, rangEnviron) values (@nom, @rang)";
    myCommand.Parameters.Add("@nom", OleDbType.VarChar).Value = nom;
    myCommand.Parameters.Add("@rang", OleDbType.Integer).Value = rang;
    myCommand.Prepare();  
    myCommand.ExecuteNonQuery();
    myConnection.Close();
    J'obtiens "OleDbCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size." à la ligne "myCommand.Prepare();"

    Merci de votre aide !

  2. #2
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 75
    Par défaut
    J'ai bien essayer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
                OleDbConnection myConnection = new OleDbConnection(connectionString);
                OleDbCommand myCommand = myConnection.CreateCommand();
                myConnection.Open();
                myCommand.CommandText = "insert into environ (NOM_ENVIRON, RANG_ENVIRON) values (@nom, @rang)";
                //myCommand.CommandText = "Insert into environ (NOM_ENVIRON,RANG_ENVIRON) values ('obieebacdev-v1',0)";
                myCommand.Parameters.Add(new OleDbParameter("@rang", OleDbType.Integer, 2)).Value = rang;
                myCommand.Parameters.Add(new OleDbParameter("@nom", OleDbType.VarChar, 35)).Value = nom;
     
                myCommand.Prepare();
                myCommand.ExecuteNonQuery();
                myConnection.Close();
    Mais ca me retourne l'erreur : ORA-00936: expression absente

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 75
    Par défaut
    CA aussi ça ne marche pas... à l'aide !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
                OleDbConnection myConnection = new OleDbConnection(connectionString);
                OleDbCommand myCommand = myConnection.CreateCommand();
                myConnection.Open();
                myCommand.CommandText = "insert into environ (NOM_ENVIRON) values (@nom)";
                myCommand.Parameters.Add(new OleDbParameter("@nom", OleDbType.VarChar, 35, "NOM_ENVIRON")).Value = nom;
                myCommand.Prepare();
                myCommand.ExecuteNonQuery();
                myConnection.Close();

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 75
    Par défaut
    Toujours pas...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
                OleDbConnection myConnection = new OleDbConnection(connectionString);
                OleDbCommand myCommand = myConnection.CreateCommand();
                myConnection.Open();
                myCommand.CommandText = "insert into environ (NOM_ENVIRON) values (@nom)";
                myCommand.Parameters.AddWithValue(@"nom", nom).OleDbType = OleDbType.VarChar;
                myCommand.Parameters[@"nom"].Size = 25;
                myCommand.Prepare();
                myCommand.ExecuteNonQuery();
                myConnection.Close();
    A l'aide !

  5. #5
    Expert confirmé Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Par défaut
    Essaye:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    myCommand.CommandText = "insert into environ (nomEnviron, rangEnviron) values (?, ?)"; 
    myCommand.Parameters.Add("nomEnviron", OleDbType.VarChar,2).Value = nom; 
    myCommand.Parameters.Add("rangEnviron", OleDbType.Integer,35).Value = rang;

  6. #6
    Membre Expert Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Par défaut
    Hello,

    essaie de juste supprimer l'appel à Prepare. Autant que je sache, elle n'est pas nécessaire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Chaine de connection sur base oracle
    Par Laye dans le forum Persistance des données
    Réponses: 2
    Dernier message: 29/06/2007, 23h05
  2. Pb Export Client 7.3.4 sur base oracle 9.2.0.6
    Par jmglbb dans le forum Administration
    Réponses: 3
    Dernier message: 09/01/2007, 15h54
  3. Réponses: 5
    Dernier message: 12/06/2006, 12h07
  4. Problleme de connection ADO sur base Oracle
    Par poirier dans le forum ASP
    Réponses: 7
    Dernier message: 08/06/2004, 09h34
  5. Réponses: 3
    Dernier message: 17/05/2004, 17h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo