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
<aspbjectdatasource 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>
<asparameter name="Id" type="Int32" />
<asparameter name="Mid" type="String" />
<asparameter name="FamilyName" type="String" />
<asparameter name="FirstName" type="String" />
<asparameter name="Flat" type="String" />
<asparameter name="House" type="String" />
<asparameter name="Street" type="String" />
<asparameter name="Mikud" type="String" />
<asparameter name="PartnerName" type="String" />
<asparameter name="Cityid" type="Int32" />
<asparameter name="TimesParticipated" type="Int32" />
<asparameter name="LastMenstrualDate" type="DateTime" />
<asparameter name="Birthdate" type="DateTime" />
<asparameter name="ScheduleDate" type="DateTime" />
<asparameter name="PregnancyWeek" type="Int32" />
</insertparameters>
</aspbjectdatasource>
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
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
<aspbjectdatasource 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>
<asparameter name="Id" type="Int32" />
<asparameter name="Mid" type="String" />
<asparameter name="FamilyName" type="String" />
<asparameter name="FirstName" type="String" />
<asparameter name="Flat" type="String" />
<asparameter name="House" type="String" />
<asparameter name="Street" type="String" />
<asparameter name="Mikud" type="String" />
<asparameter name="PartnerName" type="String" />
<asparameter name="Cityid" type="Int32" />
<asparameter name="TimesParticipated" type="Int32" />
<asparameter name="LastMenstrualDate" type="DateTime" />
<asparameter name="Birthdate" type="DateTime" />
<asparameter name="ScheduleDate" type="DateTime" />
<asparameter name="PregnancyWeek" type="Int32" />
</insertparameters>
</aspbjectdatasource>
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