Bonjour,
Pour un site en ASP.NET 2.0, je dois gérer une liste de catégories. Pour cela j'utilise un Gridview avec une SqlDaraSource (modification/suppression/visualisation) et pour l'ajout, je voudrais ajouter par l'intermédiare d'une TextBox.
J'utilise alors la méthode Insert() de ma SDS. Et la, c'est le drame!
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 <script runat="server"> private void InsertCategorie( object source, EventArgs e) { this .sdsCategorie.Insert(); } </script > [...] <span>Nouvelle cat,gorie : </span> <asp:TextBoxID="txtNouvelleCategorie"runat="server"></asp:TextBox> <asp:RequiredFieldValidatorID="rfvTxtNouvelleCategorie"Display="static"runat="server"ControlToValidate="txtNouvelleCategorie" ErrorMessage="RequiredFieldValidator">/!\ Veuillez saisir un libell, /!\</asp:RequiredFieldValidator> <asp:ButtonID="cmdAjoutCategorie" runat="server" Text="Ajouter" OnClick="InsertCategorie"/> [...] <asp:SqlDataSourceID="sdsCategorie" runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [t_categorie] WHERE [id_categorie] = @id_categorie" InsertCommand="INSERT INTO [t_categorie] ([libelle_c]) VALUES (@libelle_c)"SelectCommand="SELECT [id_categorie], [libelle_c] FROM [t_categorie] ORDER BY [libelle_c], [id_categorie]" UpdateCommand="UPDATE [t_categorie] SET [libelle_c] = @libelle_c WHERE [id_categorie] = @id_categorie"> [...] <InsertParameters> <asp:FormParameter Name="libelle_c" FormField="txtNouvelleCategorie" Type="String"/> </InsertParameters> </asp:SqlDataSource>
Mais j'ai ce message d'erreur lorsque je valide :
System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'libelle_c', table '[...]\EBUY.MDF.dbo.t_categorie'; column does not allow nulls. INSERT fails.The statement has been terminated.
Pourtant le champ est rempli!
Si quelqu'un peut m'aider^^
Bonne journée
Enjoy @+ et merci d'avance
Partager