Item has already been added. Key in dictionary

Discussion in 'ASP .Net Web Controls' started by avital, Dec 12, 2006.

  1. avital

    avital Guest

    Hi,
    When inserting a new item i get the following error: Item has already
    been added. Key in dictionary: 'Cellular' Key being added: 'Cellular'

    As far as I know you get that error if you enter the parameter more
    than once, however i can't find anywhere in my code where the value is
    entered more than once. What could be the problem?

    Thanks in advance for the help :)

    Details.aspx

    <asp:eek:bjectdatasource id="ObjectDataSource1" runat="server"
    insertmethod="InsertMomDetails"


    oninserted="Formview2_Inserted" oninserting="Numbers_Inserting"
    selectmethod="GetSingleMom"

    typename="Classes">

    <selectparameters>

    <asp:sessionparameter name="mId" sessionfield="mid" type="String" />

    </selectparameters>

    <insertparameters>

    <asp:parameter name="Id" type="Int32" />

    <asp:parameter name="Mid" type="String" />

    <asp:parameter name="FamilyName" type="String" />

    <asp:parameter name="FirstName" type="String" />

    <asp:parameter name="Flat" type="String" />

    <asp:parameter name="House" type="String" />

    <asp:parameter name="Street" type="String" />

    <asp:parameter name="Mikud" type="String" />

    <asp:parameter name="PartnerName" type="String" />

    <asp:parameter name="Cityid" type="Int32" />

    <asp:parameter name="TimesParticipated" type="Int32" />

    <asp:parameter name="LastMenstrualDate" type="DateTime" />

    <asp:parameter name="Birthdate" type="DateTime" />

    <asp:parameter name="ScheduleDate" type="DateTime" />

    <asp:parameter name="PregnancyWeek" type="Int32" />

    </insertparameters>

    </asp:eek:bjectdatasource>
    Protected Sub Numbers_Inserting(ByVal sender As Object, ByVal e As
    ObjectDataSourceMethodEventArgs)


    Dim Telephone As String

    Dim Cellular As String


    Dim cellPre As DropDownList = FormView2.FindControl("ddl_iCell")

    Dim cPre As String = cellPre.SelectedValue

    Dim cell As TextBox = FormView2.FindControl("i_Cellular")
    Cellular = cPre &

    "-" & cell.Text

    Dim ddl_iPhone As DropDownList = FormView2.FindControl("ddl_iPhone")

    Dim i_phone As TextBox = FormView2.FindControl("i_Telephone")
    Telephone = ddl_iPhone.SelectedValue &

    "-" & i_phone.Text
    e.InputParameters.Add(

    "Cellular", Cellular) -error line
    e.InputParameters.Add(

    "Telephone", Telephone)

    End Sub
    Classes.vb

    Public Function InsertMomDetails(ByVal Mid As String, _

    ByVal FamilyName As String, _

    ByVal FirstName As String, _

    ByVal Flat As String, _

    ByVal House As String, _

    ByVal Street As String, _

    ByVal Mikud As String, _

    ByVal Telephone As String, _

    ByVal Cellular As String, _

    ByVal PartnerName As String, _

    ByVal Cityid As Integer, _

    ByVal TimesParticipated As Integer, _

    ByVal LastMenstrualDate As DateTime, _

    ByVal Birthdate As DateTime, _

    ByVal ScheduleDate As DateTime, _

    ByVal PregnancyWeek As Integer)

    Dim myCommand As New SqlCommand("InsertMomDetails", myConnection)

    myCommand.CommandType = CommandType.StoredProcedure

    myCommand.Parameters.Add(New SqlParameter("@Id", SqlDbType.Int))

    myCommand.Parameters("@Id").Direction = ParameterDirection.Output

    myCommand.Parameters("@Id").SourceColumn = "Id"

    myCommand.Parameters.AddWithValue(

    "@Mid", Mid)
    myCommand.Parameters.AddWithValue(

    "@FamilyName", FamilyName)
    myCommand.Parameters.AddWithValue(

    "@FirstName", FirstName)
    myCommand.Parameters.AddWithValue(

    "@Flat", Flat)
    myCommand.Parameters.AddWithValue(

    "@House", House)
    myCommand.Parameters.AddWithValue(

    "@Street", Street)
    myCommand.Parameters.AddWithValue(

    "@Mikud", Mikud)
    myCommand.Parameters.AddWithValue(

    "@Telephone", Telephone)
    myCommand.Parameters.AddWithValue(

    "@Cellular", Cellular)
    myCommand.Parameters.AddWithValue(

    "@PartnerName", PartnerName)
    myCommand.Parameters.AddWithValue(

    "@Cityid", Cityid)
    myCommand.Parameters.AddWithValue(

    "@TimesParticipated", TimesParticipated)
    myCommand.Parameters.AddWithValue(

    "@LastMenstrualDate", LastMenstrualDate)
    myCommand.Parameters.AddWithValue(

    "@Birthdate", Birthdate)
    myCommand.Parameters.AddWithValue(

    "@Scheduledate", ScheduleDate)
    myCommand.Parameters.AddWithValue(

    "@PregnancyWeek", PregnancyWeek)
    myConnection.Open()


    Dim affectedRows As Integer = myCommand.ExecuteNonQuery()

    ''close connection
    myConnection.Close()


    Dim returnValue As Integer

    If (affectedRows > 0) Then
    returnValue = myCommand.Parameters(

    "@Id").Value

    End If

    Return returnValue

    End Function
     
    avital, Dec 12, 2006
    #1
    1. Advertising

  2. It seems to me that this error would happen if your Numbers_Inserting
    function is called more than once.
    Perhaps you should check the collection for the existence of that key before
    attempting to add it.

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net


    "avital" <> wrote in message
    news:...
    > Hi,
    > When inserting a new item i get the following error: Item has already
    > been added. Key in dictionary: 'Cellular' Key being added: 'Cellular'
    >
    > As far as I know you get that error if you enter the parameter more
    > than once, however i can't find anywhere in my code where the value is
    > entered more than once. What could be the problem?
    >
    > Thanks in advance for the help :)
    >
    > Details.aspx
    >
    > <asp:eek:bjectdatasource id="ObjectDataSource1" runat="server"
    > insertmethod="InsertMomDetails"
    >
    >
    > oninserted="Formview2_Inserted" oninserting="Numbers_Inserting"
    > selectmethod="GetSingleMom"
    >
    > typename="Classes">
    >
    > <selectparameters>
    >
    > <asp:sessionparameter name="mId" sessionfield="mid" type="String" />
    >
    > </selectparameters>
    >
    > <insertparameters>
    >
    > <asp:parameter name="Id" type="Int32" />
    >
    > <asp:parameter name="Mid" type="String" />
    >
    > <asp:parameter name="FamilyName" type="String" />
    >
    > <asp:parameter name="FirstName" type="String" />
    >
    > <asp:parameter name="Flat" type="String" />
    >
    > <asp:parameter name="House" type="String" />
    >
    > <asp:parameter name="Street" type="String" />
    >
    > <asp:parameter name="Mikud" type="String" />
    >
    > <asp:parameter name="PartnerName" type="String" />
    >
    > <asp:parameter name="Cityid" type="Int32" />
    >
    > <asp:parameter name="TimesParticipated" type="Int32" />
    >
    > <asp:parameter name="LastMenstrualDate" type="DateTime" />
    >
    > <asp:parameter name="Birthdate" type="DateTime" />
    >
    > <asp:parameter name="ScheduleDate" type="DateTime" />
    >
    > <asp:parameter name="PregnancyWeek" type="Int32" />
    >
    > </insertparameters>
    >
    > </asp:eek:bjectdatasource>
    > Protected Sub Numbers_Inserting(ByVal sender As Object, ByVal e As
    > ObjectDataSourceMethodEventArgs)
    >
    >
    > Dim Telephone As String
    >
    > Dim Cellular As String
    >
    >
    > Dim cellPre As DropDownList = FormView2.FindControl("ddl_iCell")
    >
    > Dim cPre As String = cellPre.SelectedValue
    >
    > Dim cell As TextBox = FormView2.FindControl("i_Cellular")
    > Cellular = cPre &
    >
    > "-" & cell.Text
    >
    > Dim ddl_iPhone As DropDownList = FormView2.FindControl("ddl_iPhone")
    >
    > Dim i_phone As TextBox = FormView2.FindControl("i_Telephone")
    > Telephone = ddl_iPhone.SelectedValue &
    >
    > "-" & i_phone.Text
    > e.InputParameters.Add(
    >
    > "Cellular", Cellular) -error line
    > e.InputParameters.Add(
    >
    > "Telephone", Telephone)
    >
    > End Sub
    > Classes.vb
    >
    > Public Function InsertMomDetails(ByVal Mid As String, _
    >
    > ByVal FamilyName As String, _
    >
    > ByVal FirstName As String, _
    >
    > ByVal Flat As String, _
    >
    > ByVal House As String, _
    >
    > ByVal Street As String, _
    >
    > ByVal Mikud As String, _
    >
    > ByVal Telephone As String, _
    >
    > ByVal Cellular As String, _
    >
    > ByVal PartnerName As String, _
    >
    > ByVal Cityid As Integer, _
    >
    > ByVal TimesParticipated As Integer, _
    >
    > ByVal LastMenstrualDate As DateTime, _
    >
    > ByVal Birthdate As DateTime, _
    >
    > ByVal ScheduleDate As DateTime, _
    >
    > ByVal PregnancyWeek As Integer)
    >
    > Dim myCommand As New SqlCommand("InsertMomDetails", myConnection)
    >
    > myCommand.CommandType = CommandType.StoredProcedure
    >
    > myCommand.Parameters.Add(New SqlParameter("@Id", SqlDbType.Int))
    >
    > myCommand.Parameters("@Id").Direction = ParameterDirection.Output
    >
    > myCommand.Parameters("@Id").SourceColumn = "Id"
    >
    > myCommand.Parameters.AddWithValue(
    >
    > "@Mid", Mid)
    > myCommand.Parameters.AddWithValue(
    >
    > "@FamilyName", FamilyName)
    > myCommand.Parameters.AddWithValue(
    >
    > "@FirstName", FirstName)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Flat", Flat)
    > myCommand.Parameters.AddWithValue(
    >
    > "@House", House)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Street", Street)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Mikud", Mikud)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Telephone", Telephone)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Cellular", Cellular)
    > myCommand.Parameters.AddWithValue(
    >
    > "@PartnerName", PartnerName)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Cityid", Cityid)
    > myCommand.Parameters.AddWithValue(
    >
    > "@TimesParticipated", TimesParticipated)
    > myCommand.Parameters.AddWithValue(
    >
    > "@LastMenstrualDate", LastMenstrualDate)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Birthdate", Birthdate)
    > myCommand.Parameters.AddWithValue(
    >
    > "@Scheduledate", ScheduleDate)
    > myCommand.Parameters.AddWithValue(
    >
    > "@PregnancyWeek", PregnancyWeek)
    > myConnection.Open()
    >
    >
    > Dim affectedRows As Integer = myCommand.ExecuteNonQuery()
    >
    > ''close connection
    > myConnection.Close()
    >
    >
    > Dim returnValue As Integer
    >
    > If (affectedRows > 0) Then
    > returnValue = myCommand.Parameters(
    >
    > "@Id").Value
    >
    > End If
    >
    > Return returnValue
    >
    > End Function
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Dec 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. micky
    Replies:
    0
    Views:
    1,424
    micky
    Dec 20, 2005
  2. Guest
    Replies:
    2
    Views:
    5,665
    wwwtar
    Nov 2, 2006
  3. =?Utf-8?B?Q2hyaXNGcm9obGljaA==?=

    Parser Error Message: The entry 'ConnString1' has already been add

    =?Utf-8?B?Q2hyaXNGcm9obGljaA==?=, Sep 21, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    14,035
    David R. Longnecker
    Sep 21, 2006
  4. Replies:
    1
    Views:
    18,124
  5. Marco Liedekerken

    DataKeyName GridView has already been added

    Marco Liedekerken, Nov 7, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    764
    Marco Liedekerken
    Nov 7, 2006
Loading...

Share This Page