L'insertion d'infos à ma BD bloque

Résolu
stephaneLeonelY Messages postés 18 Date d'inscription lundi 5 mars 2012 Statut Membre Dernière intervention 7 novembre 2012 - 20 avril 2012 à 13:24
cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 - 20 avril 2012 à 14:10
Salut à Tous, SVP avez vous une idée du problem que j'ai.
voici le Code:

SqlDataAdapter data = new SqlDataAdapter();

            data.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle"+
                "values("+
                 "Select V_ID from Netzplan where V_Name = '@VName')"+
                ",(select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' ))", connection);
            data.InsertCommand.Parameters.Add("@VName", SqlDbType.VarChar).Value = VorgangNameTextBox.Text;
            data.InsertCommand.Parameters.Add("@Ab", SqlDbType.VarChar).Value = AbhängigkeitenTextBox.Text;
            

            connection.Open();
            data.InsertCommand.ExecuteNonQuery();
            MessageBox.Show(" Datei eingefügt");
            connection.Close();SqlConnection connection = new SqlConnection("Data Source= .\\SQLEXPRESS;"+
            " Initial Catalogzeit; integrated security true");




Qu'est ce qui peux être la raison? et comment puis je y remedier?
merci d'avance.
The Righteous will live by faith.
Galatians 3:12

8 réponses

cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 7
20 avril 2012 à 14:01
ata.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle "+
                "values("+
                 "(Select V_ID from Netzplan where V_Name = '@VName')"+
                ",(select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' ))", connection);

j'ai fais une erreur au dessus. Ce code devrait aller
3
cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 7
20 avril 2012 à 13:29
Bonjour,
Premièrement mettre des noms de tables avec des accents c'est pas forcément une bonne idée.
Deuxièmement, il manque une espace entre le nom de ta table et le mot clef Values:
data.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle "+ 
"values("+
0
stephaneLeonelY Messages postés 18 Date d'inscription lundi 5 mars 2012 Statut Membre Dernière intervention 7 novembre 2012
20 avril 2012 à 13:41
Bonjour
merci pour l'infos j'ai fait ce dont tu m'as dit(créer l'espace) et j'ai aussi enlevé les accents et laisser tt simplement les parametres. mais je recoit cette faute


[b]Incorrect syntax near the keyword 'Select'.
Incorrect syntax near ')'.
Incorrect syntax near ')'.
/b

Comment pourrai je resoudre celà?

merci d'avance.

The Righteous will live by faith.
Galatians 3:12
0
cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 7
20 avril 2012 à 13:44
il faudrait que tu stockes ta data.InsertCommand dans une variable et que tu en affiche le contenu lors du debug. ça permettrait de voir ou est l'erreur de syntaxe.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
stephaneLeonelY Messages postés 18 Date d'inscription lundi 5 mars 2012 Statut Membre Dernière intervention 7 novembre 2012
20 avril 2012 à 13:51
et quel type pourai attribuer a ma variable? est ce de cette forme que tu parles?

data.InsertCommand = Variable;
 variable new SqlCommand("insert into AbhängigkeitTabelle values(Select V_ID from Netzplan where V_Name @VName),(select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' ))", connection);




est ainsi?
The Righteous will live by faith.
Galatians 3:12
0
cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 7
20 avril 2012 à 13:58
je pense que l'erreur est ici:
data.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle "+
                "values("+
                 "(Select V_ID from Netzplan where V_Name = '@VName')"+
                "AND (select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' ))", connection);

Sinon pour afficher ta commande, met un point d’arrêt dans ton code et fais une exécution pas a pas jusqu'à arriver a l'affectation de ta variable
0
stephaneLeonelY Messages postés 18 Date d'inscription lundi 5 mars 2012 Statut Membre Dernière intervention 7 novembre 2012
20 avril 2012 à 14:08
tu avais raison je viens de le constater il vas à la perfection.

Merci encore.

The Righteous will live by faith.
Galatians 3:12
0
cs_L0ci Messages postés 224 Date d'inscription vendredi 26 novembre 2010 Statut Membre Dernière intervention 11 juin 2013 7
20 avril 2012 à 14:10
De rien. Bonne continuation
0
Rejoignez-nous