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 :

Mode deconnecté "ADO Dotnet"


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut Mode deconnecté "ADO Dotnet"
    Bonjour en fait je debut en C# et je ss entrain de faire un formulaire avec les winforms et j'aimerai le stocker mes informations dans une base de donnee je vous montres mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
     
    namespace Simple_test_deconnecte_2
    {
        public partial class Form1 : Form
        {
            public SqlConnection connection;
            public SqlDataAdapter myDa;
            public DataSet myDs;
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the '_leader_databaseDataSet.Products' table. You can move, or remove it, as needed.
                this.productsTableAdapter.Fill(this._leader_databaseDataSet.Products);
                connection = new SqlConnection();
                myDa = new SqlDataAdapter();
                myDs = new DataSet();
     
                //connection à la base
                myDa.InsertCommand = new SqlCommand();
                myDa.InsertCommand.Connection = connection;
                connection.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=leader-database;Integrated Security=True;Pooling=False";
     
                myDa.InsertCommand.CommandText = "INSERT INTO Products (Name) " + 
                    "VALUES (@nom)";
                myDa.InsertCommand.Parameters.Add("@nom", SqlDbType.NVarChar, 50, "Name");
     
            }
     
            private void bt_send_Click(object sender, EventArgs e)
            {
                dataGridView1.DataSource = _leader_databaseDataSet.Products;
            }
        }
    }
    mon probleme est le suivant lorsque je clique mon bouton send aucune action ne se produit les donnees ne se sont pas envoyer dans la base je compte sur votre aide.Merci

  2. #2
    Membre actif
    Inscrit en
    Octobre 2007
    Messages
    236
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Octobre 2007
    Messages : 236
    Points : 233
    Points
    233
    Par défaut
    T'as préparés tous, mais t'as oublié le code de remplissage de la DataSet depuis la base de données. DataAdapter.Fill pour charger les données.

  3. #3
    Nouveau membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    Merci pour ta reponse mais je viens d'ajouter la ligne suivante

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    myDa.Fill(myDs, " Products");
    mais j'ai toujours le meme probleme aucune donnee ne s'ajoute à la base de donne voila l'integralité du code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
     
     
    namespace Simple_test_deconnecte_2
    {
        public partial class Form1 : Form
        {
            public SqlConnection connection;
            public SqlDataAdapter myDa;
            public DataSet myDs;
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the '_leader_databaseDataSet.Products' table. You can move, or remove it, as needed.
                this.productsTableAdapter.Fill(this._leader_databaseDataSet.Products);
                connection = new SqlConnection();
                myDa = new SqlDataAdapter();
                myDs = new DataSet();
     
                //connection à la base
     
                myDa.InsertCommand = new SqlCommand();
                myDa.InsertCommand.Connection = connection;
                connection.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=leader-database;Integrated Security=True;Pooling=False";
     
                myDa.Fill(myDs, " Products");
     
                myDa.InsertCommand.CommandText = "INSERT INTO Products (Name) " + 
                    "VALUES (@nom)";
     
     
     
                myDa.InsertCommand.Parameters.Add("@nom", SqlDbType.NVarChar, 50, "Name");
     
     
            }
     
            private void bt_send_Click(object sender, EventArgs e)
            {
                dataGridView1.DataSource = _leader_databaseDataSet.Products;
     
            }
        }
    }
    si quelqu'un a une idee.
    merci

  4. #4
    Membre actif
    Inscrit en
    Octobre 2007
    Messages
    236
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Octobre 2007
    Messages : 236
    Points : 233
    Points
    233
    Par défaut
    Si t'as utilisés l'EDI pour ajouter les composants DataAdapter, BindingSource alors tout le code que t'as ajouté ne sert à rien parce que l'EDI a tout mis en place et tu n'a qu'à connecter le DataGridView avec l'objet BindingSource de ta table que tu trouveras au dessous de ton formulaire (en mode Design) normatlement ça doit porter un nom comme productsBindingSource.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    dataGridView1.DataSource = productsBindingSource;

  5. #5
    Nouveau membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    tu avais raison par rapport au "productsBindingSource" qui etait present dans la partie design mais j'ai toujours le meme probleme tjrs rien dans la bd

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
     
     
    namespace Simple_test_deconnecte_2
    {
        public partial class Form1 : Form
        {
            public SqlConnection connection;
            public SqlDataAdapter myDa;
            public DataSet myDs;
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the '_leader_databaseDataSet.Products' table. You can move, or remove it, as needed.
                this.productsTableAdapter.Fill(this._leader_databaseDataSet.Products);
                connection = new SqlConnection();
                myDa = new SqlDataAdapter();
                myDs = new DataSet();
     
                //connection à la base
     
                myDa.InsertCommand = new SqlCommand();
                myDa.InsertCommand.Connection = connection;
                connection.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=leader-database;Integrated Security=True;Pooling=False";
     
                myDa.InsertCommand.CommandText = "INSERT INTO Products (Name) " + 
                    "VALUES (@nom)";
     
                myDa.InsertCommand.Parameters.Add("@nom", SqlDbType.NVarChar, 50, "Name");
     
     
            }
     
            private void bt_send_Click(object sender, EventArgs e)
            {
                dataGridView1.DataSource = productsBindingSource;
     
            }
     
        }
    }

  6. #6
    Membre actif
    Inscrit en
    Octobre 2007
    Messages
    236
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Octobre 2007
    Messages : 236
    Points : 233
    Points
    233
    Par défaut
    Ah bon, tu veux sauver le contenu de la DataGridView vers la base de données, n'est ce pas?
    Dans l'événement Click :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    TableAdapterManager.UpdateAll(DataSet);

  7. #7
    Nouveau membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 46
    Points : 36
    Points
    36
    Par défaut
    oui c'est bien ca je veux que les element soit sauvegarder dans la DataGridView

    et lorsque j'ajoute "TableAdapterManager.UpdateAll(DataSet);" il ne reconnait pas cette commande bon perso je sais plus trop quoi faire je pense que je laisse la partie du DataGridView pour mettre les donnees dans la base sans passé par lui si tu as un conseil à me donnee je ss preneur.
    Merci

  8. #8
    Membre actif
    Inscrit en
    Octobre 2007
    Messages
    236
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Octobre 2007
    Messages : 236
    Points : 233
    Points
    233
    Par défaut
    Je me suis mal expliqué :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    TableAdapterManager.UpdateAll(DataSet);
    C'est le prototype de la fonction que tu peux utiliser pour envoyer les données en mode déconnecté de l'application vers la base de données.
    TableAdapterManager : Le nom de ton instance de la classe TableAdapterManager.
    DataSet : Le nom de ton instance de la classe DataSet.

Discussions similaires

  1. [Débutant] ado.net mode deconnecté
    Par saintjuste dans le forum ADO.NET
    Réponses: 1
    Dernier message: 13/03/2013, 13h05
  2. Réponses: 4
    Dernier message: 11/05/2006, 16h57
  3. Réponses: 2
    Dernier message: 13/06/2005, 15h37

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