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
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
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" /> <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" /> <asp:Button ID="Button_Annuler" runat="server" Text="Annuler" OnClick="Button_Annuler_Click" /> </td> </tr> </table> </div> </form> </body> </html>
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); } } }
Partager