Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0IDENTITY_INSERT OFF problemIDENTITY_INSERT OFF problem
Previous
 
Next
New Post
3/23/2009 11:23 PM
 

when i try to use my custom News module  I got the folowing  problem impossible explecite insert value within column identity when IDENTITY_INSERT est défini OFF. despite when i look at News table I notice that the insert has been performed (I got this error exactly when I Click the Insert button) please I need help

 

--------------News Table------------------

NewsID (primary key)

TabID

Titre

Contenue

 

--------------------------------------Code behiend-----------------------------------------

 

Imports DotNetNuke

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Collections.Generic

Imports System.Reflection

Imports System.Text

Imports DotNetNuke.Security.PortalSecurity

 

 

    Partial Class DesktopModules_News_News

    Inherits Entities.Modules.PortalModuleBase

 

    'Dim WithEvents con As SqlConnection

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

        Me.GridView1.Visible = True

        'Dim marquee As New StringBuilder

        'Dim page As New StringBuilder

        'Dim invisibleMarquee As New StringBuilder

        'con = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")

 

        '' Create the command object

        'Dim str As String = "SELECT TabName, Titre, Contenue FROM News, Tabs Where Tabs.TabID = News.TabID"

        'Dim cmd As New SqlCommand(str, con)

 

        'Dim da As New SqlDataAdapter(cmd)

 

        'Dim ds As New DataSet()

 

        'da.Fill(ds, "News")

 

        ''Dim dc As DataColumn

        ''For Each dc In ds.Tables(0).Columns

        ''    invisibleMarquee.Appendformat("{0,15}", dc.ColumnName)

        ''Next

 

        ''invisibleMarquee.Append(vbCrLf & "<br>")

 

        'Dim dr As DataRow

        'For Each dr In ds.Tables(0).Rows

 

        '    Dim i As Integer

        '    marquee.Append("&nbsp; &nbsp; &nbsp;")

        '    For i = 1 To ds.Tables(0).Columns.Count

        '        If i = 1 Then

        '            page.Replace(dr(1).ToString, "")

        '            page = page.Appendformat("{0}", dr(i - 1))

        '            marquee.Replace(dr(i - 1).ToString, "")

        '        ElseIf i = 2 Then

        '            marquee.Appendformat("<FONT SIZE='4' FACE='courier' COLOR='red'>")

        '            marquee.Appendformat("{0}", dr(i - 1))

        '            marquee.Appendformat(": ")

        '            marquee.Appendformat("</FONT>")

 

        '        ElseIf i = 3 Then

        '            marquee.Appendformat("<a href=?tabname=" & page.ToString & ">{0}</a>", dr(i - 1))

        '            'marquee.Appendformat(" &nbsp;:")

        '        End If

 

        '    Next i

        '    marquee.Append(vbCrLf & "&nbsp;&nbsp; &nbsp;<b>:::</b>")

 

        'Next

        'Label2.Text = "<MARQUEE onmouseover=this.stop(); onmouseout=this.start(); WIDTH=100% BEHAVIOR=SCROLL DIRECTION=LEFT BGColor=silver>" & marquee.ToString & "</MARQUEE>"

        'Response.Write(page)

    End Sub

 

 

    Protected Sub InsertItemButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim TabID As Label = formView1.FindControl("LblChoicedTab")

        Dim DropDownList1 As DropDownList = formView1.FindControl("DropDownList1")

        TabID.Text = DropDownList1.SelectedValue

        Dim Titre As TextBox = formView1.FindControl("TextBoxTitreNews")

        Dim Contenue As TextBox = formView1.FindControl("TextBoxContenueNews")

 

        Dim Connection As System.Data.SqlClient.SqlConnection

        Connection = New System.Data.SqlClient.SqlConnection

        Connection.ConnectionString = "server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40"

 

        Connection.Open()

        Dim Command As System.Data.SqlClient.SqlCommand

        Dim SQL As String

 

        SQL = "INSERT INTO [News](TabID,Titre,Contenue) VALUES('" & TabID.Text & "','" & Titre.Text & "','" & Contenue.Text & "')"

        Command = New System.Data.SqlClient.SqlCommand(SQL, Connection)

        Command.ExecuteNonQuery()

        Connection.Close()

 

        Me.formView1.Visible = False

        LinkButtonAddNewNews.Text = "News Successfully Added - Click To Add Another"

 

    End Sub

 

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim TabID As Label = formView1.FindControl("LblChoicedTab")

        Dim DropDownList1 As DropDownList = formView1.FindControl("DropDownList1")

        TabID.Text = DropDownList1.SelectedValue

 

    End Sub

 

 

 

    Protected Sub InsertCancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Me.formView1.Visible = False

 

    End Sub

 

    Protected Sub LinkButtonAddNewNews_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonAddNewNews.Click

        Me.formView1.Visible = True

    End Sub

 

 

End Class

 

 

--------------------------------------------------------------------------------the controle code------------------------------------------------------------------------------------------------

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="News.ascx.vb" Inherits="DesktopModules_News_News" %>

 

 

 

 

<asp:formView ID="formView1" runat="server" 

DataKeyNames="NewsID" 

DataSourceID="SqlDataSource1"

    DefaultMode="Insert" CellPadding="4" ForeColor="#333333" Visible="False">

    <EditItemTemplate>

    </EditItemTemplate>

    <InsertItemTemplate>

<table style="width: 454px; height: 264px">

    <tr>

        <td colspan="3">

            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<strong> News Module</strong></td>

    </tr>

    <tr>

        <td style="width: 2px; height: 36px">

            <asp:Label ID="LblTitreNews" runat="server" Text="Titre" Width="143px"></asp:Label></td>

        <td style="width: 21px; height: 36px">

        </td>

        <td style="width: 11px; height: 36px">

            <asp:TextBox ID="TextBoxTitreNews" runat="server" Text='<%# Bind("Titre") %>'></asp:TextBox></td>

    </tr>

    <tr>

        <td style="width: 2px; height: 136px">

            <asp:Label ID="Label1" runat="server" Text="Contenue" Width="141px"></asp:Label></td>

        <td style="width: 21px; height: 136px">

        </td>

        <td style="width: 11px; height: 136px">

            <asp:TextBox ID="TextBoxContenueNews" runat="server" Text='<%# Bind("Contenue") %>' Height="81px" Width="222px"></asp:TextBox>

    </tr>

    <tr>

        <td style="width: 2px; height: 25px">

            TabID</td>

        <td style="width: 21px; height: 25px">

        </td>

        <td style="width: 11px; height: 25px">

            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"

                DataTextField="TabName" DataValueField="TabID" Width="143px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

            </asp:DropDownList><br />

            <asp:Label ID="LblChoicedTab" runat="server" Text='<%# Bind("TabID") %>' Width="170px" Visible="False"></asp:Label></td>

    </tr>

    <tr>

        <td style="width: 2px; height: 25px">

        </td>

        <td style="width: 21px; height: 25px">

        </td>

        <td style="width: 11px; height: 25px">

            </td>

    </tr>

     <tr>

                    <td style="width: 100px">

                    </td>

                    <td style="width: 23px">

                    </td>

                    <td style="width: 112px">

             <asp:LinkButton ID="InsertItemButton" runat="server" 

                 CausesValidation="True" CommandName="Insert"

                 Text="Insert" OnClick="InsertItemButton_Click">

             </asp:LinkButton>

             <asp:LinkButton ID="InsertCancelButton" runat="server" 

                 CausesValidation="False" CommandName="Cancel"

                 Text="Cancel" OnClick="InsertCancelButton_Click">

             </asp:LinkButton></td>

                </tr>

</table>

</InsertItemTemplate>

     <ItemTemplate>

     </ItemTemplate>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

</asp:formView>

&nbsp;<asp:LinkButton ID="LinkButtonAddNewNews" runat="server">Add New News</asp:LinkButton><br />

<br />

<asp:Label ID="Label2" runat="server" Height="139px" Width="796px"></asp:Label><br />

<%--<table>

    <tr>

        <td style="width: 100px; height: 21px">

        </td>

        <td style="width: 234px; height: 21px">

        </td>

        <td style="width: 114px; height: 21px">

<asp:Button ID="ButtonInsertNews" runat="server" Text="News Insert" Width="97px" /></td>

    </tr>

</table>--%>

<br />

<br />

<br />

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"

    DataKeyNames="NewsID" DataSourceID="SqlDataSource1" EmptyDataText="Il n'y a aucun enregistrement de données à afficher."

    ForeColor="#333333" GridLines="None" Visible="False" AllowPaging="True">

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <Columns>

        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

        <asp:BoundField DataField="NewsID" HeaderText="NewsID" ReadOnly="True" SortExpression="NewsID" />

        <asp:BoundField DataField="TabID" HeaderText="TabID" SortExpression="TabID" />

        <asp:BoundField DataField="Titre" HeaderText="Titre" SortExpression="Titre" />

        <asp:BoundField DataField="Contenue" HeaderText="Contenue" SortExpression="Contenue" />

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID" InsertCommand="INSERT INTO [News] ([NewsID], [TabID], [Titre], [Contenue]) VALUES (@NewsID, @TabID, @Titre, @Contenue)"

    ProviderName="<%$ ConnectionStrings:DotNetNuke40ConnectionString1.ProviderName %>"

    SelectCommand="SELECT [NewsID], [TabID], [Titre], [Contenue] FROM [News]" UpdateCommand="UPDATE [News] SET [TabID] = @TabID, [Titre] = @Titre, [Contenue] = @Contenue WHERE [NewsID] = @NewsID">

    <DeleteParameters>

        <asp:Parameter Name="NewsID" Type="Int32" />

    </DeleteParameters>

    <InsertParameters>

        <asp:Parameter Name="NewsID" Type="Int32" />

        <asp:Parameter Name="TabID" Type="Int32" />

        <asp:Parameter Name="Titre" Type="String" />

        <asp:Parameter Name="Contenue" Type="String" />

    </InsertParameters>

    <UpdateParameters>

        <asp:Parameter Name="TabID" Type="Int32" />

        <asp:Parameter Name="Titre" Type="String" />

        <asp:Parameter Name="Contenue" Type="String" />

        <asp:Parameter Name="NewsID" Type="Int32" />

    </UpdateParameters>

</asp:SqlDataSource>

<br />

<br />

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CellPadding="4"

    DataKeyNames="TabID" DataSourceID="SqlDataSource2" EmptyDataText="Il n'y a aucun enregistrement de données à afficher."

    ForeColor="#333333" GridLines="None" Visible="False">

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <Columns>

        <asp:BoundField DataField="TabID" HeaderText="TabID" InsertVisible="False" ReadOnly="True"

            SortExpression="TabID" />

        <asp:BoundField DataField="TabOrder" HeaderText="TabOrder" SortExpression="TabOrder" />

        <asp:BoundField DataField="PortalID" HeaderText="PortalID" SortExpression="PortalID" />

        <asp:BoundField DataField="TabName" HeaderText="TabName" SortExpression="TabName" />

        <asp:CheckBoxField DataField="IsVisible" HeaderText="IsVisible" SortExpression="IsVisible" />

        <asp:BoundField DataField="ParentId" HeaderText="ParentId" SortExpression="ParentId" />

        <asp:CheckBoxField DataField="DisableLink" HeaderText="DisableLink" SortExpression="DisableLink" />

        <asp:CheckBoxField DataField="IsDeleted" HeaderText="IsDeleted" SortExpression="IsDeleted" />

        <asp:BoundField DataField="Url" HeaderText="Url" SortExpression="Url" />

        <asp:BoundField DataField="TabPath" HeaderText="TabPath" SortExpression="TabPath" />

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    DeleteCommand="DELETE FROM [Tabs] WHERE [TabID] = @TabID" InsertCommand="INSERT INTO [Tabs] ([TabOrder], [PortalID], [TabName], [IsVisible], [ParentId], [DisableLink], [IsDeleted], [Url], [TabPath]) VALUES (@TabOrder, @PortalID, @TabName, @IsVisible, @ParentId, @DisableLink, @IsDeleted, @Url, @TabPath)"

    ProviderName="<%$ ConnectionStrings:DotNetNuke40ConnectionString1.ProviderName %>"

    SelectCommand="SELECT [TabID], [TabOrder], [PortalID], [TabName], [IsVisible], [ParentId], [DisableLink], [IsDeleted], [Url], [TabPath] FROM [Tabs]"

    UpdateCommand="UPDATE [Tabs] SET [TabOrder] = @TabOrder, [PortalID] = @PortalID, [TabName] = @TabName, [IsVisible] = @IsVisible, [ParentId] = @ParentId, [DisableLink] = @DisableLink, [IsDeleted] = @IsDeleted, [Url] = @Url, [TabPath] = @TabPath WHERE [TabID] = @TabID">

    <DeleteParameters>

        <asp:Parameter Name="TabID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

        <asp:Parameter Name="TabOrder" Type="Int32" />

        <asp:Parameter Name="PortalID" Type="Int32" />

        <asp:Parameter Name="TabName" Type="String" />

        <asp:Parameter Name="IsVisible" Type="Boolean" />

        <asp:Parameter Name="ParentId" Type="Int32" />

        <asp:Parameter Name="DisableLink" Type="Boolean" />

        <asp:Parameter Name="IsDeleted" Type="Boolean" />

        <asp:Parameter Name="Url" Type="String" />

        <asp:Parameter Name="TabPath" Type="String" />

        <asp:Parameter Name="TabID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

        <asp:Parameter Name="TabOrder" Type="Int32" />

        <asp:Parameter Name="PortalID" Type="Int32" />

        <asp:Parameter Name="TabName" Type="String" />

        <asp:Parameter Name="IsVisible" Type="Boolean" />

        <asp:Parameter Name="ParentId" Type="Int32" />

        <asp:Parameter Name="DisableLink" Type="Boolean" />

        <asp:Parameter Name="IsDeleted" Type="Boolean" />

        <asp:Parameter Name="Url" Type="String" />

        <asp:Parameter Name="TabPath" Type="String" />

    </InsertParameters>

</asp:SqlDataSource>

&nbsp;<br />

<br />

&nbsp;&nbsp;

 

 

 
New Post
3/24/2009 10:22 AM
 

thanks the problem was resolved by lookink at the Controle code modify the code at line "115" for the insert statment for the "SqlDataSource1" controle from :

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID" InsertCommand="INSERT INTO [News] ([NewsID], [TabID], [Titre], [Contenue]) VALUES (@NewsID, @TabID, @Titre, @Contenue)"

 

to

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    DeleteCommand="DELETE FROM [News] WHERE [NewsID] = @NewsID" InsertCommand="INSERT INTO [News] ([TabID], [Titre], [Contenue]) VALUES (@TabID, @Titre, @Contenue)"

 

by eliminate the NewsID field 

 

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0IDENTITY_INSERT OFF problemIDENTITY_INSERT OFF problem


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out