Bonjour
je develoope avec vs2005 aveec C#
et j'ai cette erreur
Impossible d'insérer la valeur NULL dans la colonne 'GRPARTCODE', table 'StockBase.dbo.STKGROUPEARTICLE'. Cette colonne n'accepte pas les valeurs NULL. INSERT a échoué.
L'instruction a été arrêtée.
Description : Une exception non gérée s'est produite au moment de l'exécution de la demande Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.
Détails de l'exception: System.Data.SqlClient.SqlException: Impossible d'insérer la valeur NULL dans la colonne 'GRPARTCODE', table 'StockBase.dbo.STKGROUPEARTICLE'. Cette colonne n'accepte pas les valeurs NULL. INSERT a échoué.
L'instruction a été arrêtée.
Erreur source:
Ligne 22 : protected void btAjouter_Click(object sender, EventArgs e)
Ligne 23 : {
Ligne 24 : sourceGrpArt.Insert();
Ligne 25 : dgGrpArt.EditIndex = dgGrpArt.Rows.Count;
Ligne 26 : dgGrpArt.DataBind();
Fichier source : c:\Inetpub\wwwroot\Stock\grpArticle.aspx.cs Ligne : 24
Trace de la pile:
[SqlException (0x80131904): Impossible d'insérer la valeur NULL dans la colonne 'GRPARTCODE', table 'StockBase.dbo.STKGROUPEARTICLE'. Cette colonne n'accepte pas les valeurs NULL. INSERT a échoué.
L'instruction a été arrêtée.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +925466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800118
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +149
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +404
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +447
System.Web.UI.WebControls.SqlDataSource.Insert() +13
grpArticle.btAjouter_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Stock\grpArticle.aspx.cs:24
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
--------------------------------------------------------------------------------
Informations sur la version : Version Microsoft .NET Framework :2.0.50727.1433; Version ASP.NET :2.0.50727.1433
alors que mon code semble bon
et dans le codebehind
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 <form id="form1" runat="server"> <div> <asp:GridView ID="dgGrpArt" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="GRPARTCODE" DataSourceID="sourceGrpArt" ForeColor="#333333" GridLines="None" Style="z-index: 100; left: 3px; position: absolute; top: 0px" Font-Size="8pt" ShowFooter="True" DataMember="DefaultView" > <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <Columns> <asp:TemplateField HeaderText="Code" SortExpression="GRPARTCODE"> <EditItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("GRPARTCODE") %>'></asp:Label> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("GRPARTCODE") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="GRPARTCODE" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Libellé" SortExpression="GRPARTLIBELLE"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("GRPARTLIBELLE") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("GRPARTLIBELLE") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="GRPARTLIBELLE" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Mettre à jour"></asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Annuller"></asp:LinkButton> </EditItemTemplate> <FooterTemplate> <asp:Button ID="btAjouter" runat="server" Text="Ajouter" CommandName="ajouter" OnClick="btAjouter_Click" Font-Bold="True" Font-Size="8pt" /> </FooterTemplate> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Modifier"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <asp:SqlDataSource ID="sourceGrpArt" runat="server" ConnectionString="<%$ ConnectionStrings:StockBaseConnectionString %>" SelectCommand="SELECT [GRPARTCODE], [GRPARTLIBELLE] FROM [STKGROUPEARTICLE]" InsertCommand="INSERT INTO [STKGROUPEARTICLE] ([GRPARTCODE], [GRPARTLIBELLE]) VALUES (@GRPARTCODE, @GRPARTLIBELLE)" DeleteCommand="DELETE FROM [STKGROUPEARTICLE] WHERE [GRPARTCODE] = @GRPARTCODE" UpdateCommand="UPDATE [STKGROUPEARTICLE] SET [GRPARTLIBELLE] = @GRPARTLIBELLE WHERE [GRPARTCODE] = @GRPARTCODE"> <InsertParameters> <asp:Parameter Name="GRPARTCODE" Type="String" /> <asp:Parameter Name="GRPARTLIBELLE" Type="String" /> </InsertParameters> <DeleteParameters> <asp:Parameter Name="GRPARTCODE" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="GRPARTLIBELLE" Type="String" /> <asp:Parameter Name="GRPARTCODE" Type="String" /> </UpdateParameters> </asp:SqlDataSource> </div> </form>
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 using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class grpArticle : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { dgGrpArt.DataBind(); } } protected void btAjouter_Click(object sender, EventArgs e) { sourceGrpArt.Insert(); dgGrpArt.EditIndex = dgGrpArt.Rows.Count; dgGrpArt.DataBind(); } }
merci beaucoup
Partager