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 :

Le textBox n'existe pas dans ce contexte


Sujet :

C#

  1. #1
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    183
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 183
    Points : 78
    Points
    78
    Par défaut Le textBox n'existe pas dans ce contexte
    Bonjour tout le monde,
    j'ai fait une petite application web avec VS 2012 et en essayant de connecter cette application à une base de donnée pour y entrer des données je reçois une erreur qui me dit que le TextBox_Titre n'existe pas dans ce contexte, mais pourtant il existe , voici mon bout de code:

    Default.aspx
    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
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"  Theme="MonApparence" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
     
    </script>
     
    <html >
    <head id="Head1" runat="server">
        <title>Gestion des thèmes avec ASP.NET 2.0 et C#</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="centre">
        <table width="350px">
        <tr>
            <td colspan="2">
                <asp:Image ID="Image_Fleche" SkinID="Fleche" runat="server" />&nbsp;
                <asp:Label ID="Label_Title" SkinID="Title" runat="server" Text="Formulaire d'ajout d'un nouveau livre"></asp:Label>
            </td>
        </tr>
        <tr>
            <td style="width: 100px;"><asp:Label ID="Label_Titre" runat="server" Text="Titre "></asp:Label></td>
            <td style="width: 250px;"><asp:TextBox ID="TextBox_Titre" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td><asp:Label ID="Label_Auteur" runat="server" Text="Auteur "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Auteur" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td><asp:Label ID="Label_Catégorie" runat="server" Text="Catégorie "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Catégorie" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Collection" runat="server" Text="Collection "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Collection" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Langue" runat="server" Text="Langue"></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Langue" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Editeur" runat="server" Text="Editeur"></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Editeur" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <br />
                <asp:Button ID="Button_Valider" runat="server" Text="Valider" OnClick="Button_Valider_Click" Width="60px" />&nbsp;
                            <asp:Button ID="Button_Annuler" runat="server" Text="Annuler" OnClick="Button_Annuler_Click" />&nbsp;
                &nbsp;
                </td>
        </tr>
        </table>
        </div>
        </form>
    </body>
    </html>
    Default.aspx.cs

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.OleDb;
     
    namespace WebApplication1
    {
        public partial class _default  :System.Web.UI.Page
        {
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Documents\Visual Studio 2012\Projects\WebApplication1\livre.accdb");
            protected void Page_Load(object sender, EventArgs e)
            {
                con.Open();
     
            }
     
     
            protected void Button_Valider_Click(object sender, EventArgs e)
            {
                string vaq1 = string.Format("insert into livre values((0)",TextBox_Titre);
            }
     
     
     
     
        }
     
     
    }

  2. #2
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    183
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 183
    Points : 78
    Points
    78
    Par défaut Le textBox n'existe pas dans ce contexte
    Bonjour tout le monde,
    j'ai fait une petite application web avec VS 2012 et en essayant de connecter cette application à une base de donnée pour y entrer des données je reçois une erreur qui me dit que le TextBox_Titre n'existe pas dans ce contexte, mais pourtant il existe , voici mon bout de code:

    Default.aspx
    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
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"  Theme="MonApparence" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
     
    </script>
     
    <html >
    <head id="Head1" runat="server">
        <title>Gestion des thèmes avec ASP.NET 2.0 et C#</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="centre">
        <table width="350px">
        <tr>
            <td colspan="2">
                <asp:Image ID="Image_Fleche" SkinID="Fleche" runat="server" />&nbsp;
                <asp:Label ID="Label_Title" SkinID="Title" runat="server" Text="Formulaire d'ajout d'un nouveau livre"></asp:Label>
            </td>
        </tr>
        <tr>
            <td style="width: 100px;"><asp:Label ID="Label_Titre" runat="server" Text="Titre "></asp:Label></td>
            <td style="width: 250px;"><asp:TextBox ID="TextBox_Titre" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td><asp:Label ID="Label_Auteur" runat="server" Text="Auteur "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Auteur" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td><asp:Label ID="Label_Catégorie" runat="server" Text="Catégorie "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Catégorie" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Collection" runat="server" Text="Collection "></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Collection" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Langue" runat="server" Text="Langue"></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Langue" runat="server"></asp:TextBox></td>
        </tr>
            <tr>
            <td><asp:Label ID="Label_Editeur" runat="server" Text="Editeur"></asp:Label></td>
            <td><asp:TextBox ID="TextBox_Editeur" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <br />
                <asp:Button ID="Button_Valider" runat="server" Text="Valider" OnClick="Button_Valider_Click" Width="60px" />&nbsp;
                            <asp:Button ID="Button_Annuler" runat="server" Text="Annuler" OnClick="Button_Annuler_Click" />&nbsp;
                &nbsp;
                </td>
        </tr>
        </table>
        </div>
        </form>
    </body>
    </html>
    Default.aspx.cs
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.OleDb;
     
    namespace WebApplication1
    {
        public partial class _default  :System.Web.UI.Page
        {
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Documents\Visual Studio 2012\Projects\WebApplication1\livre.accdb");
            protected void Page_Load(object sender, EventArgs e)
            {
                con.Open();
     
            }
     
     
            protected void Button_Valider_Click(object sender, EventArgs e)
            {
                string vaq1 = string.Format("insert into livre values((0)",TextBox_Titre);
            }
     
     
     
     
        }
     
     
    }

  3. #3
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2012
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Juin 2012
    Messages : 87
    Points : 179
    Points
    179
    Par défaut
    Hello,

    Le code suivant devrait insérer le contenu de la textbox_titre dans ta table livre (à supposer qu'elle ne contienne qu'un seul champ).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    protected void Button_Valider_Click(object sender, EventArgs e)
    {
        Dim Command As New OleDbCommand("INSERT INTO livre VALUES (@Titre)", con)
        Command.Parameters.Add(New OleDbParameter("@Titre", TextBox_Titre.Text))
        Command.ExecuteNonQuery()
    }
    Ne pas oublier le .Text apres Textbox_Titre sans quoi ça marchera pas.

    Cdlt,
    MvK

Discussions similaires

  1. [Débutant] Le textBox n'existe pas dans ce contexte
    Par kryptong dans le forum Visual Studio
    Réponses: 0
    Dernier message: 23/12/2012, 15h30
  2. Erreur: Le nom n'existe pas dans le contexte actuel
    Par khawlita dans le forum Accès aux données
    Réponses: 1
    Dernier message: 07/04/2009, 18h37
  3. Le nom 'ctrl' n'existe pas dans le contexte actuel
    Par altair8080 dans le forum C#
    Réponses: 0
    Dernier message: 04/11/2008, 18h56
  4. Réponses: 3
    Dernier message: 25/06/2008, 14h01
  5. 'N'existe pas dans le contexte actuel' dès que condition
    Par wazodnuit dans le forum ASP.NET
    Réponses: 3
    Dernier message: 01/09/2007, 20h09

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