Item has already been added. Key in dictionary

A

avital

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
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top