0
protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlAddGroup.InsertParameters["mem_email"].DefaultValue = Session["User"].ToString();
            SqlAddGroup.InsertParameters["groupname"].DefaultValue = Txtgroup.Text;
            SqlAddGroup.Insert();
            Label1.Text = "Group has been added";
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }



<asp:SqlDataSource ID="SqlAddGroup" runat="server" 
                    ConflictDetection="CompareAllValues" 
                    ConnectionString="<%$ ConnectionStrings:PadmaSMSConnectionString %>" 
                    DeleteCommand="DELETE FROM [group] WHERE [sno] = @original_sno AND [mem_email] = @original_mem_email AND [groupname] = @original_groupname" 
                    InsertCommand="INSERT INTO [group] ([mem_email], [groupname], [sno]) VALUES (@mem_email, @groupname, @sno)" 
                    OldValuesParameterFormatString="original_{0}" 
                    SelectCommand="SELECT * FROM [group] WHERE ([mem_email] = @mem_email)" 

                    UpdateCommand="UPDATE [group] SET [mem_email] = @mem_email, [groupname] = @groupname WHERE [sno] = @original_sno AND [mem_email] = @original_mem_email AND [groupname] = @original_groupname">
                    <DeleteParameters>
                        <asp:Parameter Name="original_sno" Type="Int32" />
                        <asp:Parameter Name="original_mem_email" Type="String" />
                        <asp:Parameter Name="original_groupname" Type="String" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="mem_email" Type="String" />
                        <asp:Parameter Name="groupname" Type="String" />
                        <asp:Parameter Name="sno" Type="Int32" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:SessionParameter Name="mem_email" SessionField="User" Type="String" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="mem_email" Type="String" />
                        <asp:Parameter Name="groupname" Type="String" />
                        <asp:Parameter Name="original_sno" Type="Int32" />
                        <asp:Parameter Name="original_mem_email" Type="String" />
                        <asp:Parameter Name="original_groupname" Type="String" />
                    </UpdateParameters>
                </asp:SqlDataSource>

My problem is that I am getting this exception whenever i run the code for insertion. Can someone please help me discover where exactly am I going wrong?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by atinobrian
0

Cannot insert explicit value for identity column in table 'group' when IDEN ????

Please post the full sentence of your error message ...

I think the problem lies in your primary key, maybe its not set to auto-increment or something...

Hope this helps.

0

you are trying to pass sno as a parameter, Is sno an auto generated Identity key column ? if so then you cannot pass value to sno while inserting as the values will be autogenerated . In any case kindly post more details

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.