Précédent   Forum du club des développeurs et IT Pro > Dotnet > Langages > C#
C# Forum d'entraide sur la programmation C#. Avant de poster -> FAQ C#, Articles C#, Sources C#
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 23/12/2012, 15h29   #1
kryptong
Membre du Club
 
Femme
Étudiant
Inscription : janvier 2012
Messages : 160
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2012
Messages : 160
Points : 43
Points : 43
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 :
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 :
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);
        }
 
 
 
 
    }
 
 
}
kryptong est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/12/2012, 15h30   #2
kryptong
Membre du Club
 
Femme
Étudiant
Inscription : janvier 2012
Messages : 160
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : Tunisie

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2012
Messages : 160
Points : 43
Points : 43
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 :
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 :
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);
        }
 
 
 
 
    }
 
 
}
kryptong est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/12/2012, 11h52   #3
MvK0610
Membre régulier
 
Homme Fabien
Développeur .NET
Inscription : juin 2012
Messages : 61
Détails du profil
Informations personnelles :
Nom : Homme Fabien
Localisation : France, Savoie (Rhône Alpes)

Informations professionnelles :
Activité : Développeur .NET
Secteur : Transports

Informations forums :
Inscription : juin 2012
Messages : 61
Points : 88
Points : 88
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 :
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
__________________
Les questions ne sont pas obligées d'avoir du sens. Mais les réponses, si.
Terry Pratchett (Procrastination)
MvK0610 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 14h31.


 
 
 
 
Partenaires

Hébergement Web